SoPlex Documentation
Loading...
Searching...
No Matches
Rational Class Reference

#include <rational.h>

Public Member Functions

Construction and destruction
void rationalErrorMessage () const
 
 Rational ()
 default constructor
 
 Rational (const Rational &r)
 copy constructor
 
 Rational (const long double &r)
 constructor from long double
 
 Rational (const double &r)
 constructor from double
 
 Rational (const int &i)
 constructor from int
 
 Rational (const Integer &num, const Integer &den)
 constructor from Integer
 
 Rational (const mpq_t &q)
 constructor from mpq_t (GMP only)
 
 ~Rational ()
 destructor
 
Rationaloperator= (const Rational &)
 assignment operator
 
Rationaloperator= (const long double &r)
 assignment operator from long double
 
Rationaloperator= (const double &r)
 assignment operator from double
 
Rationaloperator= (const int &i)
 assignment operator from int
 
Rationaloperator= (const mpq_t &q)
 assignment operator from mpq_t
 
void assign (const Rational &)
 
void assign (const long double &r)
 
void assign (const double &r)
 
void assign (const int &i)
 
Typecasts
 operator double () const
 
 operator long double () const
 
 operator float () const
 
Arithmetic operators
Rational operator+ (const Rational &r) const
 addition operator
 
Rational operator+= (const Rational &r)
 addition assignment operator
 
Rational operator+ (const double &r) const
 addition operator for doubles
 
Rational operator+= (const double &r)
 addition assignment operator for doubles
 
Rational operator+ (const int &r) const
 addition operator for ints
 
Rational operator+= (const int &r)
 addition assignment operator for ints
 
Rational operator- (const Rational &r) const
 subtraction operator
 
Rational operator-= (const Rational &r)
 subtraction assignment operator
 
Rational operator- (const double &r) const
 subtraction operator for doubles
 
Rational operator-= (const double &r)
 subtraction assignment operator for doubles
 
Rational operator- (const int &r) const
 subtraction operator for ints
 
Rational operator-= (const int &r)
 subtraction assignment operator for ints
 
Rational operator* (const Rational &r) const
 multiplication operator
 
Rational operator*= (const Rational &r)
 multiplication assignment operator operator
 
Rational operator* (const double &r) const
 multiplication operator for doubles
 
Rational operator*= (const double &r)
 multiplication assignment operator for doubles
 
Rational operator* (const int &r) const
 multiplication operator for ints
 
Rational operator*= (const int &r)
 multiplication assignment operator for ints
 
Rational operator/ (const Rational &r) const
 division operator
 
Rational operator/= (const Rational &r)
 division assignment operator
 
Rational operator/ (const double &r) const
 division operator for doubles
 
Rational operator/= (const double &r)
 division assignment operator for doubles
 
Rational operator/ (const int &r) const
 division operator for ints
 
Rational operator/= (const int &r)
 division assignment operator for ints
 
RationaladdProduct (const Rational &r, const Rational &s)
 add product of two rationals
 
RationalsubProduct (const Rational &r, const Rational &s)
 subtract product of two rationals
 
RationaladdQuotient (const Rational &r, const Rational &s)
 add quotient of two rationals, r divided by s
 
RationalsubQuotient (const Rational &r, const Rational &s)
 subtract quotient of two rationals, r divided by s
 
Methods for checking exactness of doubles
bool isAdjacentTo (const double &d) const
 checks if d is exactly equal to the Rational and if not, if it is one of the two adjacent doubles
 
Methods for querying size
int sizeInBase (const int base=2) const
 Size in specified base (bit size for base 2)
 

Friends

Friends
int compareRational (const Rational &r, const Rational &s)
 
bool operator!= (const Rational &r, const Rational &s)
 
bool operator== (const Rational &r, const Rational &s)
 
bool operator< (const Rational &r, const Rational &s)
 
bool operator<= (const Rational &r, const Rational &s)
 
bool operator> (const Rational &r, const Rational &s)
 
bool operator>= (const Rational &r, const Rational &s)
 
bool operator!= (const Rational &r, const double &s)
 
bool operator== (const Rational &r, const double &s)
 
bool operator< (const Rational &r, const double &s)
 
bool operator<= (const Rational &r, const double &s)
 
bool operator> (const Rational &r, const double &s)
 
bool operator>= (const Rational &r, const double &s)
 
bool operator!= (const double &r, const Rational &s)
 
bool operator== (const double &r, const Rational &s)
 
bool operator< (const double &r, const Rational &s)
 
bool operator<= (const double &r, const Rational &s)
 
bool operator> (const double &r, const Rational &s)
 
bool operator>= (const double &r, const Rational &s)
 
bool operator!= (const Rational &r, const long double &s)
 
bool operator== (const Rational &r, const long double &s)
 
bool operator< (const Rational &r, const long double &s)
 
bool operator<= (const Rational &r, const long double &s)
 
bool operator> (const Rational &r, const long double &s)
 
bool operator>= (const Rational &r, const long double &s)
 
bool operator!= (const long double &r, const Rational &s)
 
bool operator== (const long double &r, const Rational &s)
 
bool operator< (const long double &r, const Rational &s)
 
bool operator<= (const long double &r, const Rational &s)
 
bool operator> (const long double &r, const Rational &s)
 
bool operator>= (const long double &r, const Rational &s)
 
bool operator!= (const Rational &r, const float &s)
 
bool operator== (const Rational &r, const float &s)
 
bool operator< (const Rational &r, const float &s)
 
bool operator<= (const Rational &r, const float &s)
 
bool operator> (const Rational &r, const float &s)
 
bool operator>= (const Rational &r, const float &s)
 
bool operator!= (const float &r, const Rational &s)
 
bool operator== (const float &r, const Rational &s)
 
bool operator< (const float &r, const Rational &s)
 
bool operator<= (const float &r, const Rational &s)
 
bool operator> (const float &r, const Rational &s)
 
bool operator>= (const float &r, const Rational &s)
 
Rational operator+ (const double &d, const Rational &r)
 
Rational operator- (const double &d, const Rational &r)
 
Rational operator* (const double &d, const Rational &r)
 
Rational operator/ (const double &d, const Rational &r)
 
bool operator!= (const Rational &r, const int &s)
 
bool operator== (const Rational &r, const int &s)
 
bool operator< (const Rational &r, const int &s)
 
bool operator<= (const Rational &r, const int &s)
 
bool operator> (const Rational &r, const int &s)
 
bool operator>= (const Rational &r, const int &s)
 
bool operator!= (const int &r, const Rational &s)
 
bool operator== (const int &r, const Rational &s)
 
bool operator< (const int &r, const Rational &s)
 
bool operator<= (const int &r, const Rational &s)
 
bool operator> (const int &r, const Rational &s)
 
bool operator>= (const int &r, const Rational &s)
 
Rational operator+ (const int &d, const Rational &r)
 
Rational operator- (const int &d, const Rational &r)
 
Rational operator* (const int &d, const Rational &r)
 
Rational operator/ (const int &d, const Rational &r)
 
Rational spxAbs (const Rational &r)
 
int sign (const Rational &r)
 
Rational operator- (const Rational &q)
 

Conversion from and to String

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

Detailed Description

Definition at line 236 of file rational.h.

Constructor & Destructor Documentation

◆ Rational() [1/7]

Rational ( )

default constructor

Definition at line 251 of file rational.h.

◆ Rational() [2/7]

Rational ( const Rational & r)

copy constructor

Definition at line 255 of file rational.h.

◆ Rational() [3/7]

Rational ( const long double & r)

constructor from long double

Definition at line 259 of file rational.h.

◆ Rational() [4/7]

Rational ( const double & r)

constructor from double

Definition at line 263 of file rational.h.

◆ Rational() [5/7]

Rational ( const int & i)

constructor from int

Definition at line 267 of file rational.h.

◆ Rational() [6/7]

Rational ( const Integer & num,
const Integer & den )

constructor from Integer

Definition at line 271 of file rational.h.

◆ Rational() [7/7]

Rational ( const mpq_t & q)

constructor from mpq_t (GMP only)

Definition at line 275 of file rational.h.

◆ ~Rational()

~Rational ( )

destructor

Definition at line 286 of file rational.h.

Member Function Documentation

◆ addProduct()

Rational & addProduct ( const Rational & r,
const Rational & s )

add product of two rationals

Definition at line 523 of file rational.h.

References rationalErrorMessage().

◆ addQuotient()

Rational & addQuotient ( const Rational & r,
const Rational & s )

add quotient of two rationals, r divided by s

Definition at line 537 of file rational.h.

References rationalErrorMessage().

◆ assign() [1/4]

void assign ( const double & r)

Definition at line 324 of file rational.h.

References rationalErrorMessage().

◆ assign() [2/4]

void assign ( const int & i)

Definition at line 328 of file rational.h.

References rationalErrorMessage().

◆ assign() [3/4]

void assign ( const long double & r)

Definition at line 320 of file rational.h.

References rationalErrorMessage().

◆ assign() [4/4]

void assign ( const Rational & )

Definition at line 316 of file rational.h.

References rationalErrorMessage().

◆ isAdjacentTo()

bool isAdjacentTo ( const double & d) const

checks if d is exactly equal to the Rational and if not, if it is one of the two adjacent doubles

Definition at line 557 of file rational.h.

References rationalErrorMessage().

◆ operator double()

operator double ( ) const

Definition at line 336 of file rational.h.

◆ operator float()

operator float ( ) const

Definition at line 344 of file rational.h.

◆ operator long double()

operator long double ( ) const

Definition at line 340 of file rational.h.

◆ operator*() [1/3]

Rational operator* ( const double & r) const

multiplication operator for doubles

Definition at line 463 of file rational.h.

References rationalErrorMessage().

◆ operator*() [2/3]

Rational operator* ( const int & r) const

multiplication operator for ints

Definition at line 475 of file rational.h.

References rationalErrorMessage().

◆ operator*() [3/3]

Rational operator* ( const Rational & r) const

multiplication operator

Definition at line 451 of file rational.h.

References rationalErrorMessage().

◆ operator*=() [1/3]

Rational operator*= ( const double & r)

multiplication assignment operator for doubles

Definition at line 469 of file rational.h.

References rationalErrorMessage().

◆ operator*=() [2/3]

Rational operator*= ( const int & r)

multiplication assignment operator for ints

Definition at line 481 of file rational.h.

References rationalErrorMessage().

◆ operator*=() [3/3]

Rational operator*= ( const Rational & r)

multiplication assignment operator operator

Definition at line 457 of file rational.h.

References rationalErrorMessage().

◆ operator+() [1/3]

Rational operator+ ( const double & r) const

addition operator for doubles

Definition at line 391 of file rational.h.

References rationalErrorMessage().

◆ operator+() [2/3]

Rational operator+ ( const int & r) const

addition operator for ints

Definition at line 403 of file rational.h.

References rationalErrorMessage().

◆ operator+() [3/3]

Rational operator+ ( const Rational & r) const

addition operator

Definition at line 379 of file rational.h.

References rationalErrorMessage().

◆ operator+=() [1/3]

Rational operator+= ( const double & r)

addition assignment operator for doubles

Definition at line 397 of file rational.h.

References rationalErrorMessage().

◆ operator+=() [2/3]

Rational operator+= ( const int & r)

addition assignment operator for ints

Definition at line 409 of file rational.h.

References rationalErrorMessage().

◆ operator+=() [3/3]

Rational operator+= ( const Rational & r)

addition assignment operator

Definition at line 385 of file rational.h.

References rationalErrorMessage().

◆ operator-() [1/3]

Rational operator- ( const double & r) const

subtraction operator for doubles

Definition at line 427 of file rational.h.

References rationalErrorMessage().

◆ operator-() [2/3]

Rational operator- ( const int & r) const

subtraction operator for ints

Definition at line 439 of file rational.h.

References rationalErrorMessage().

◆ operator-() [3/3]

Rational operator- ( const Rational & r) const

subtraction operator

Definition at line 415 of file rational.h.

References rationalErrorMessage().

◆ operator-=() [1/3]

Rational operator-= ( const double & r)

subtraction assignment operator for doubles

Definition at line 433 of file rational.h.

References rationalErrorMessage().

◆ operator-=() [2/3]

Rational operator-= ( const int & r)

subtraction assignment operator for ints

Definition at line 445 of file rational.h.

References rationalErrorMessage().

◆ operator-=() [3/3]

Rational operator-= ( const Rational & r)

subtraction assignment operator

Definition at line 421 of file rational.h.

References rationalErrorMessage().

◆ operator/() [1/3]

Rational operator/ ( const double & r) const

division operator for doubles

Definition at line 499 of file rational.h.

References rationalErrorMessage().

◆ operator/() [2/3]

Rational operator/ ( const int & r) const

division operator for ints

Definition at line 511 of file rational.h.

References rationalErrorMessage().

◆ operator/() [3/3]

Rational operator/ ( const Rational & r) const

division operator

Definition at line 487 of file rational.h.

References rationalErrorMessage().

◆ operator/=() [1/3]

Rational operator/= ( const double & r)

division assignment operator for doubles

Definition at line 505 of file rational.h.

References rationalErrorMessage().

◆ operator/=() [2/3]

Rational operator/= ( const int & r)

division assignment operator for ints

Definition at line 517 of file rational.h.

References rationalErrorMessage().

◆ operator/=() [3/3]

Rational operator/= ( const Rational & r)

division assignment operator

Definition at line 493 of file rational.h.

References rationalErrorMessage().

◆ operator=() [1/5]

Rational & operator= ( const double & r)

assignment operator from double

Definition at line 301 of file rational.h.

◆ operator=() [2/5]

Rational & operator= ( const int & i)

assignment operator from int

Definition at line 306 of file rational.h.

◆ operator=() [3/5]

Rational & operator= ( const long double & r)

assignment operator from long double

Definition at line 296 of file rational.h.

◆ operator=() [4/5]

Rational & operator= ( const mpq_t & q)

assignment operator from mpq_t

Definition at line 311 of file rational.h.

◆ operator=() [5/5]

Rational & operator= ( const Rational & )

assignment operator

Definition at line 291 of file rational.h.

◆ rationalErrorMessage()

◆ sizeInBase()

int sizeInBase ( const int base = 2) const

Size in specified base (bit size for base 2)

Definition at line 570 of file rational.h.

References rationalErrorMessage().

◆ str()

std::string str ( ) const

Definition at line 586 of file rational.h.

References rationalErrorMessage().

◆ subProduct()

Rational & subProduct ( const Rational & r,
const Rational & s )

subtract product of two rationals

Definition at line 530 of file rational.h.

References rationalErrorMessage().

◆ subQuotient()

Rational & subQuotient ( const Rational & r,
const Rational & s )

subtract quotient of two rationals, r divided by s

Definition at line 544 of file rational.h.

References rationalErrorMessage().

Friends And Related Symbol Documentation

◆ compareRational

int compareRational ( const Rational & r,
const Rational & s )
friend

Definition at line 596 of file rational.h.

◆ operator!= [1/9]

bool operator!= ( const double & r,
const Rational & s )
friend

Definition at line 663 of file rational.h.

◆ operator!= [2/9]

bool operator!= ( const float & r,
const Rational & s )
friend

Definition at line 787 of file rational.h.

◆ operator!= [3/9]

bool operator!= ( const int & r,
const Rational & s )
friend

Definition at line 870 of file rational.h.

◆ operator!= [4/9]

bool operator!= ( const long double & r,
const Rational & s )
friend

Definition at line 725 of file rational.h.

◆ operator!= [5/9]

bool operator!= ( const Rational & r,
const double & s )
friend

Definition at line 632 of file rational.h.

◆ operator!= [6/9]

bool operator!= ( const Rational & r,
const float & s )
friend

Definition at line 756 of file rational.h.

◆ operator!= [7/9]

bool operator!= ( const Rational & r,
const int & s )
friend

Definition at line 839 of file rational.h.

◆ operator!= [8/9]

bool operator!= ( const Rational & r,
const long double & s )
friend

Definition at line 694 of file rational.h.

◆ operator!= [9/9]

bool operator!= ( const Rational & r,
const Rational & s )
friend

Definition at line 601 of file rational.h.

◆ operator* [1/2]

Rational operator* ( const double & d,
const Rational & r )
friend

Definition at line 828 of file rational.h.

◆ operator* [2/2]

Rational operator* ( const int & d,
const Rational & r )
friend

Definition at line 911 of file rational.h.

◆ operator+ [1/2]

Rational operator+ ( const double & d,
const Rational & r )
friend

Definition at line 818 of file rational.h.

◆ operator+ [2/2]

Rational operator+ ( const int & d,
const Rational & r )
friend

Definition at line 901 of file rational.h.

◆ operator- [1/3]

Rational operator- ( const double & d,
const Rational & r )
friend

Definition at line 823 of file rational.h.

◆ operator- [2/3]

Rational operator- ( const int & d,
const Rational & r )
friend

Definition at line 906 of file rational.h.

◆ operator- [3/3]

Rational operator- ( const Rational & q)
friend

Definition at line 932 of file rational.h.

◆ operator/ [1/2]

Rational operator/ ( const double & d,
const Rational & r )
friend

Definition at line 833 of file rational.h.

◆ operator/ [2/2]

Rational operator/ ( const int & d,
const Rational & r )
friend

Definition at line 916 of file rational.h.

◆ operator< [1/9]

bool operator< ( const double & r,
const Rational & s )
friend

Definition at line 673 of file rational.h.

◆ operator< [2/9]

bool operator< ( const float & r,
const Rational & s )
friend

Definition at line 797 of file rational.h.

◆ operator< [3/9]

bool operator< ( const int & r,
const Rational & s )
friend

Definition at line 880 of file rational.h.

◆ operator< [4/9]

bool operator< ( const long double & r,
const Rational & s )
friend

Definition at line 735 of file rational.h.

◆ operator< [5/9]

bool operator< ( const Rational & r,
const double & s )
friend

Definition at line 642 of file rational.h.

◆ operator< [6/9]

bool operator< ( const Rational & r,
const float & s )
friend

Definition at line 766 of file rational.h.

◆ operator< [7/9]

bool operator< ( const Rational & r,
const int & s )
friend

Definition at line 849 of file rational.h.

◆ operator< [8/9]

bool operator< ( const Rational & r,
const long double & s )
friend

Definition at line 704 of file rational.h.

◆ operator< [9/9]

bool operator< ( const Rational & r,
const Rational & s )
friend

Definition at line 611 of file rational.h.

◆ operator<<

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

Definition at line 581 of file rational.h.

◆ operator<= [1/9]

bool operator<= ( const double & r,
const Rational & s )
friend

Definition at line 678 of file rational.h.

◆ operator<= [2/9]

bool operator<= ( const float & r,
const Rational & s )
friend

Definition at line 802 of file rational.h.

◆ operator<= [3/9]

bool operator<= ( const int & r,
const Rational & s )
friend

Definition at line 885 of file rational.h.

◆ operator<= [4/9]

bool operator<= ( const long double & r,
const Rational & s )
friend

Definition at line 740 of file rational.h.

◆ operator<= [5/9]

bool operator<= ( const Rational & r,
const double & s )
friend

Definition at line 647 of file rational.h.

◆ operator<= [6/9]

bool operator<= ( const Rational & r,
const float & s )
friend

Definition at line 771 of file rational.h.

◆ operator<= [7/9]

bool operator<= ( const Rational & r,
const int & s )
friend

Definition at line 854 of file rational.h.

◆ operator<= [8/9]

bool operator<= ( const Rational & r,
const long double & s )
friend

Definition at line 709 of file rational.h.

◆ operator<= [9/9]

bool operator<= ( const Rational & r,
const Rational & s )
friend

Definition at line 616 of file rational.h.

◆ operator== [1/9]

bool operator== ( const double & r,
const Rational & s )
friend

Definition at line 668 of file rational.h.

◆ operator== [2/9]

bool operator== ( const float & r,
const Rational & s )
friend

Definition at line 792 of file rational.h.

◆ operator== [3/9]

bool operator== ( const int & r,
const Rational & s )
friend

Definition at line 875 of file rational.h.

◆ operator== [4/9]

bool operator== ( const long double & r,
const Rational & s )
friend

Definition at line 730 of file rational.h.

◆ operator== [5/9]

bool operator== ( const Rational & r,
const double & s )
friend

Definition at line 637 of file rational.h.

◆ operator== [6/9]

bool operator== ( const Rational & r,
const float & s )
friend

Definition at line 761 of file rational.h.

◆ operator== [7/9]

bool operator== ( const Rational & r,
const int & s )
friend

Definition at line 844 of file rational.h.

◆ operator== [8/9]

bool operator== ( const Rational & r,
const long double & s )
friend

Definition at line 699 of file rational.h.

◆ operator== [9/9]

bool operator== ( const Rational & r,
const Rational & s )
friend

Definition at line 606 of file rational.h.

◆ operator> [1/9]

bool operator> ( const double & r,
const Rational & s )
friend

Definition at line 683 of file rational.h.

◆ operator> [2/9]

bool operator> ( const float & r,
const Rational & s )
friend

Definition at line 807 of file rational.h.

◆ operator> [3/9]

bool operator> ( const int & r,
const Rational & s )
friend

Definition at line 890 of file rational.h.

◆ operator> [4/9]

bool operator> ( const long double & r,
const Rational & s )
friend

Definition at line 745 of file rational.h.

◆ operator> [5/9]

bool operator> ( const Rational & r,
const double & s )
friend

Definition at line 652 of file rational.h.

◆ operator> [6/9]

bool operator> ( const Rational & r,
const float & s )
friend

Definition at line 776 of file rational.h.

◆ operator> [7/9]

bool operator> ( const Rational & r,
const int & s )
friend

Definition at line 859 of file rational.h.

◆ operator> [8/9]

bool operator> ( const Rational & r,
const long double & s )
friend

Definition at line 714 of file rational.h.

◆ operator> [9/9]

bool operator> ( const Rational & r,
const Rational & s )
friend

Definition at line 621 of file rational.h.

◆ operator>= [1/9]

bool operator>= ( const double & r,
const Rational & s )
friend

Definition at line 688 of file rational.h.

◆ operator>= [2/9]

bool operator>= ( const float & r,
const Rational & s )
friend

Definition at line 812 of file rational.h.

◆ operator>= [3/9]

bool operator>= ( const int & r,
const Rational & s )
friend

Definition at line 895 of file rational.h.

◆ operator>= [4/9]

bool operator>= ( const long double & r,
const Rational & s )
friend

Definition at line 750 of file rational.h.

◆ operator>= [5/9]

bool operator>= ( const Rational & r,
const double & s )
friend

Definition at line 657 of file rational.h.

◆ operator>= [6/9]

bool operator>= ( const Rational & r,
const float & s )
friend

Definition at line 781 of file rational.h.

◆ operator>= [7/9]

bool operator>= ( const Rational & r,
const int & s )
friend

Definition at line 864 of file rational.h.

◆ operator>= [8/9]

bool operator>= ( const Rational & r,
const long double & s )
friend

Definition at line 719 of file rational.h.

◆ operator>= [9/9]

bool operator>= ( const Rational & r,
const Rational & s )
friend

Definition at line 626 of file rational.h.

◆ sign

int sign ( const Rational & r)
friend

Definition at line 927 of file rational.h.

◆ spxAbs

Rational spxAbs ( const Rational & r)
friend

Definition at line 922 of file rational.h.