Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
nmx::apps::x011::Rational Class Reference

Rational Klasse für rationale Zahlen. More...

#include <x011.h>

Public Types

template<class X , class Y >
using is_candidate_t = std::enable_if_t< std::is_same_v< X, Rational >||std::is_same_v< Y, Rational > >
 

Public Member Functions

 Rational (long long n=0, long long d=1)
 Rational Konstruktor. More...
 
auto num () const
 num lese ... More...
 
auto den () const
 den lese... More...
 
void simplify ()
 simplify vereinfache Bruch More...
 
 operator double () const
 operator double Darstellung als reelle Zahl More...
 
template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rationaloperator+= (const T &r)
 operator += More...
 
template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rationaloperator-= (const T &r)
 operator -= More...
 
template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rationaloperator*= (const T &r)
 operator *= More...
 
template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rationaloperator/= (const T &r)
 operator /= More...
 

Static Public Attributes

template<class T >
static constexpr bool is_int_like_v
 
template<class T >
static constexpr bool is_rational_like_v
 

Friends

template<class X , class Y , class FN >
auto helpfn (const X &arg1, const Y &arg2, FN fn)
 helpfn Hilfsfunktion zur Implementierung von +,-,*,/ More...
 
template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator+ (const X &x, const Y &y)
 
template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator- (const X &x, const Y &y)
 
template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator* (const X &x, const Y &y)
 
template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator/ (const X &x, const Y &y)
 
template<typename X , typename Y , is_candidate_t< X, Y > * = nullptr>
bool operator== (const X &x, const Y &y)
 operator == Vergleichsoperator More...
 
template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
bool operator!= (const X &r1, const Y &r2)
 operator != Vergleichsoperator More...
 
template<class T >
auto pow (const Rational &r, T n)
 pow potenziere rationale Zahl More...
 
Rational inverse (const Rational &r)
 invert inverse rationale Zahl More...
 
Rational operator- (const Rational &r)
 negate eine rationale Zahl wird negiert More...
 
std::ostream & operator<< (std::ostream &os, const Rational &r)
 operator << Ausgabe einer rationalen Zahl More...
 

Detailed Description

Rational Klasse für rationale Zahlen.

Definition at line 21 of file x011.h.

Member Typedef Documentation

◆ is_candidate_t

template<class X , class Y >
using nmx::apps::x011::Rational::is_candidate_t = std::enable_if_t<std::is_same_v<X, Rational> || std::is_same_v<Y, Rational> >

zur Implementierung von +,-,*,/ sind nur rationale Zahlen zugelassen. X oder Y muss eine rationale Zahl sein

Definition at line 187 of file x011.h.

Constructor & Destructor Documentation

◆ Rational()

nmx::apps::x011::Rational::Rational ( long long  n = 0,
long long  d = 1 
)
inline

Rational Konstruktor.

Parameters
nNenner
dZähler

Definition at line 32 of file x011.h.

Member Function Documentation

◆ den()

auto nmx::apps::x011::Rational::den ( ) const
inline

den lese...

Returns
Nenner

Definition at line 54 of file x011.h.

◆ num()

auto nmx::apps::x011::Rational::num ( ) const
inline

num lese ...

Returns
Zähler

Definition at line 48 of file x011.h.

◆ operator double()

nmx::apps::x011::Rational::operator double ( ) const
inlineexplicit

operator double Darstellung als reelle Zahl

Definition at line 68 of file x011.h.

◆ operator*=()

template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rational& nmx::apps::x011::Rational::operator*= ( const T &  r)
inline

operator *=

Parameters
rganze oder rationale Zahl
Returns
Referenz auf aufrufendes Objekt

Definition at line 127 of file x011.h.

◆ operator+=()

template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rational& nmx::apps::x011::Rational::operator+= ( const T &  r)
inline

operator +=

Parameters
rganze oder rationale Zahl
Returns
Referenz auf aufrufendes Objekt

Definition at line 93 of file x011.h.

◆ operator-=()

template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rational& nmx::apps::x011::Rational::operator-= ( const T &  r)
inline

operator -=

Parameters
rganze oder rationale Zahl
Returns
Referenz auf aufrufendes Objekt

Definition at line 110 of file x011.h.

◆ operator/=()

template<class T , std::enable_if_t< is_rational_like_v< T >> * = nullptr>
Rational& nmx::apps::x011::Rational::operator/= ( const T &  r)
inline

operator /=

Parameters
rganze oder rationale Zahl
Returns
Referenz auf aufrufendes Objekt

Definition at line 144 of file x011.h.

◆ simplify()

void nmx::apps::x011::Rational::simplify ( )
inline

simplify vereinfache Bruch

Definition at line 59 of file x011.h.

Friends And Related Function Documentation

◆ helpfn

template<class X , class Y , class FN >
auto helpfn ( const X &  arg1,
const Y &  arg2,
FN  fn 
)
friend

helpfn Hilfsfunktion zur Implementierung von +,-,*,/

Parameters
arg1reelle, ganze oder rationale Zahl
arg2reelle, ganze oder rationale Zahl
fnlambda Funktion für +,-,*,/ z.B. [](double &x, double y){ return x+=y; }

Definition at line 165 of file x011.h.

◆ inverse

Rational inverse ( const Rational r)
friend

invert inverse rationale Zahl

Parameters
rrationale Zahl
Returns
1/r

Definition at line 267 of file x011.h.

◆ operator!=

template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
bool operator!= ( const X &  r1,
const Y &  r2 
)
friend

operator != Vergleichsoperator

Parameters
r1rationale Zahl
r2rationale Zahl
Returns
true wenn die rationalen Zahlen nicht gleich sind

Definition at line 238 of file x011.h.

◆ operator*

template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator* ( const X &  x,
const Y &  y 
)
friend

Definition at line 204 of file x011.h.

◆ operator+

template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator+ ( const X &  x,
const Y &  y 
)
friend

Implementierung von +,-,*,/ Funktionen werden nur dann vom Compiler erzeugt, wenn Z oder Y eine rationale Zahl ist.

Definition at line 194 of file x011.h.

◆ operator- [1/2]

template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator- ( const X &  x,
const Y &  y 
)
friend

Definition at line 199 of file x011.h.

◆ operator- [2/2]

Rational operator- ( const Rational r)
friend

negate eine rationale Zahl wird negiert

Parameters
rrationale Zahl
Returns
-r

Definition at line 276 of file x011.h.

◆ operator/

template<class X , class Y , is_candidate_t< X, Y > * = nullptr>
auto operator/ ( const X &  x,
const Y &  y 
)
friend

Definition at line 209 of file x011.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Rational r 
)
friend

operator << Ausgabe einer rationalen Zahl

Parameters
osAusgabestrom
rrationale Zahl
Returns
Referenz auf Ausgabestrom

Definition at line 286 of file x011.h.

◆ operator==

template<typename X , typename Y , is_candidate_t< X, Y > * = nullptr>
bool operator== ( const X &  x,
const Y &  y 
)
friend

operator == Vergleichsoperator

Parameters
r1rationale Zahl
r2rationale Zahl
Returns
true wenn die rationalen Zahlen gleich sind

Definition at line 220 of file x011.h.

◆ pow

template<class T >
auto pow ( const Rational r,
n 
)
friend

pow potenziere rationale Zahl

Parameters
rrationale Zahl
nPotenz
Returns
rationale Zahl wenn x ganzzahlig ist

Definition at line 249 of file x011.h.

Member Data Documentation

◆ is_int_like_v

template<class T >
constexpr bool nmx::apps::x011::Rational::is_int_like_v
static
Initial value:
=
(std::is_arithmetic_v<T> &&std::is_integral_v<T>
&& !std::is_same_v<T, bool> && !std::is_same_v<T, char>)

Test: ist T eine ganze Zahl? std::is_arithmetic_v true wenn z.B. int, bool, float,... std::is_integral_v true wenn z.B. int, bool, char,...

Definition at line 78 of file x011.h.

◆ is_rational_like_v

template<class T >
constexpr bool nmx::apps::x011::Rational::is_rational_like_v
static
Initial value:
=
is_int_like_v<T> || std::is_same_v<T, Rational>

Definition at line 84 of file x011.h.


The documentation for this class was generated from the following file: