Arkulib
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Arkulib::ERational< FloatType > Class Template Reference

This class can be used to express big rationals. More...

#include <ERational.hpp>

Public Member Functions

constexpr ERational ()
 Default constructor : instantiate an object without parameters. More...
 
template<typename IntType = int>
constexpr ERational (IntType numerator, IntType denominator, bool willBeReduce=false, bool willDenominatorBeVerified=true)
 Classic constructor : create an experimental rational from a numerator and a denominator (set default at 1) More...
 
template<typename FloatingType >
constexpr ERational (const FloatingType &nonRational)
 Create an experimental rational from a floating number. More...
 
constexpr ERational (const ERational< FloatType > &reference)=default
 Copy constructor. More...
 
template<typename IntType >
constexpr ERational (const Rational< IntType > &reference)
 Copy constructor from a Rational. More...
 
constexpr ERational (FloatType numMultiplier, short int numExponent, FloatType denMultiplier, short int denExponent)
 Explicit constructor. More...
 
constexpr ERational (std::pair< FloatType, short int > numerator, std::pair< FloatType, short int > denominator)
 Explicit constructor with std::pair. More...
 
 ~ERational ()=default
 Default Destructor. More...
 
constexpr std::pair< FloatType, short int > getNumerator () const noexcept
 
constexpr FloatType getNumMultiplier () const noexcept
 
constexpr short int getNumExponent () const noexcept
 
constexpr std::pair< FloatType, short int > getDenominator () const noexcept
 
constexpr FloatType getDenMultiplier () const noexcept
 
constexpr short int getDenExponent () const noexcept
 
constexpr void setNumerator (std::pair< FloatType, short int > numerator) noexcept
 
constexpr void setNumerator (FloatType newMultiplier, short int newExponent) noexcept
 
constexpr void setNumMultiplier (FloatType newNumMultiplier) noexcept
 
constexpr void setNumExponent (short int newNumExponent) noexcept
 
constexpr void setDenominator (std::pair< FloatType, short int > denominator) noexcept
 
constexpr void setDenominator (FloatType newMultiplier, short int newExponent) noexcept
 
constexpr void setDenMultiplier (FloatType newDenMultiplier) noexcept
 
constexpr void setDenExponent (short int newDenExponent) noexcept
 
constexpr ERational< FloatType > operator+ (const ERational< FloatType > &anotherERational) const
 Sum operation between 2 experimental rationals. More...
 
constexpr ERational< FloatType > operator- (const ERational< FloatType > &anotherERational) const
 Subtraction operation between 2 experimental rationals. More...
 
constexpr ERational< FloatType > operator* (const ERational< FloatType > &anotherERational) const
 Multiplication operation between 2 experimental rationals. More...
 
constexpr ERational< FloatType > operator/ (const ERational< FloatType > &anotherERational) const
 Division operation between 2 experimental rationals. More...
 
constexpr bool operator== (const ERational< FloatType > &anotherERational) const
 Comparison between 2 ERationals. More...
 
constexpr bool operator!= (const ERational< FloatType > &anotherERational) const
 Different comparison between 2 erationals. More...
 
bool isNegative () const noexcept
 
bool isInteger () const noexcept
 
bool isZero () const noexcept
 
constexpr ERational< FloatType > abs () const
 Apply absolute value on the ERational. More...
 
constexpr ERational< FloatType > inverse () const
 Get the inverse of an ERational. More...
 
constexpr ERational< FloatType > simplify () noexcept
 Simplify the Rational with GCD. More...
 
template<typename AnotherFloatType = double>
constexpr AnotherFloatType toRealNumber () const noexcept
 Get an approximation floating point number of the experimental ratio. More...
 
std::string toString () const noexcept
 Return ( numerator / denominator ) as a string. More...
 
template<typename AnotherFloatType >
constexpr ERational (const AnotherFloatType &nonRational)
 
template<typename IntType >
constexpr std::pair< FloatType, short > transformOperandToPair (IntType operand)
 

Private Member Functions

template<typename IntType = int>
constexpr void transformToExperimental (IntType numerator, IntType denominator)
 Set the parameters from a normal numerator and denominator. More...
 
constexpr void verifyDenominator (bool checkIfDenominatorIsNull=true)
 Verify if the denominator is null or negative. More...
 
constexpr void verifyTemplateType () const
 Verify if the template is correct. Throw an exception if the template is an integral. More...
 
constexpr void setAtSameNumeratorExponent (ERational< FloatType > &firstERational, ERational< FloatType > &secondERational) const
 Set firstERational and secondERational with the same numerator exponent. More...
 
constexpr void setAtSameDenominator (ERational< FloatType > &firstERational, ERational< FloatType > &secondERational) const
 Set firstERational and secondERational with the same denominator exponent. More...
 

Static Private Member Functions

template<typename IntType = int>
static constexpr std::pair< FloatType, short int > transformOperandToPair (IntType operand)
 Transform a numerator/denominator into a pair. More...
 

Private Attributes

std::pair< FloatType, short int > m_numerator
 
std::pair< FloatType, short int > m_denominator
 

Detailed Description

template<typename FloatType = double>
class Arkulib::ERational< FloatType >

This class can be used to express big rationals.

Template Parameters
FloatType

Definition at line 21 of file ERational.hpp.

Constructor & Destructor Documentation

◆ ERational() [1/8]

template<typename FloatType >
constexpr Arkulib::ERational< FloatType >::ERational
explicitconstexpr

Default constructor : instantiate an object without parameters.

Definition at line 346 of file ERational.hpp.

◆ ERational() [2/8]

template<typename FloatType >
template<typename IntType >
constexpr Arkulib::ERational< FloatType >::ERational ( IntType  numerator,
IntType  denominator,
bool  willBeReduce = false,
bool  willDenominatorBeVerified = true 
)
explicitconstexpr

Classic constructor : create an experimental rational from a numerator and a denominator (set default at 1)

Parameters
numerator
denominator
willBeReduce
willDenominatorBeVerified

Definition at line 353 of file ERational.hpp.

◆ ERational() [3/8]

template<typename FloatType = double>
template<typename FloatingType >
constexpr Arkulib::ERational< FloatType >::ERational ( const FloatingType &  nonRational)
explicitconstexpr

Create an experimental rational from a floating number.

Template Parameters
FloatingType
Parameters
nonRational

◆ ERational() [4/8]

template<typename FloatType = double>
constexpr Arkulib::ERational< FloatType >::ERational ( const ERational< FloatType > &  reference)
inlineconstexprdefault

Copy constructor.

Template Parameters
IntType
Parameters
reference

◆ ERational() [5/8]

template<typename FloatType = double>
template<typename IntType >
constexpr Arkulib::ERational< FloatType >::ERational ( const Rational< IntType > &  reference)
inlineexplicitconstexpr

Copy constructor from a Rational.

Parameters
reference

Definition at line 69 of file ERational.hpp.

◆ ERational() [6/8]

template<typename FloatType >
constexpr Arkulib::ERational< FloatType >::ERational ( FloatType  numMultiplier,
short int  numExponent,
FloatType  denMultiplier,
short int  denExponent 
)
constexpr

Explicit constructor.

Parameters
numMultiplier
numExponent
denMultiplier
denExponent

Definition at line 385 of file ERational.hpp.

◆ ERational() [7/8]

template<typename FloatType >
constexpr Arkulib::ERational< FloatType >::ERational ( std::pair< FloatType, short int >  numerator,
std::pair< FloatType, short int >  denominator 
)
constexpr

Explicit constructor with std::pair.

Parameters
numerator
denominator

Definition at line 397 of file ERational.hpp.

◆ ~ERational()

template<typename FloatType = double>
Arkulib::ERational< FloatType >::~ERational ( )
inlinedefault

Default Destructor.

◆ ERational() [8/8]

template<typename FloatType = double>
template<typename AnotherFloatType >
constexpr Arkulib::ERational< FloatType >::ERational ( const AnotherFloatType &  nonRational)
constexpr

Definition at line 375 of file ERational.hpp.

Member Function Documentation

◆ getNumerator()

template<typename FloatType = double>
constexpr std::pair< FloatType, short int > Arkulib::ERational< FloatType >::getNumerator ( ) const
inlineconstexprnoexcept

Definition at line 104 of file ERational.hpp.

◆ getNumMultiplier()

template<typename FloatType = double>
constexpr FloatType Arkulib::ERational< FloatType >::getNumMultiplier ( ) const
inlineconstexprnoexcept

Definition at line 105 of file ERational.hpp.

◆ getNumExponent()

template<typename FloatType = double>
constexpr short int Arkulib::ERational< FloatType >::getNumExponent ( ) const
inlineconstexprnoexcept

Definition at line 106 of file ERational.hpp.

◆ getDenominator()

template<typename FloatType = double>
constexpr std::pair< FloatType, short int > Arkulib::ERational< FloatType >::getDenominator ( ) const
inlineconstexprnoexcept

Definition at line 108 of file ERational.hpp.

◆ getDenMultiplier()

template<typename FloatType = double>
constexpr FloatType Arkulib::ERational< FloatType >::getDenMultiplier ( ) const
inlineconstexprnoexcept

Definition at line 109 of file ERational.hpp.

◆ getDenExponent()

template<typename FloatType = double>
constexpr short int Arkulib::ERational< FloatType >::getDenExponent ( ) const
inlineconstexprnoexcept

Definition at line 110 of file ERational.hpp.

◆ setNumerator() [1/2]

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setNumerator ( std::pair< FloatType, short int >  numerator)
inlineconstexprnoexcept

Definition at line 116 of file ERational.hpp.

◆ setNumerator() [2/2]

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setNumerator ( FloatType  newMultiplier,
short int  newExponent 
)
inlineconstexprnoexcept

Definition at line 117 of file ERational.hpp.

◆ setNumMultiplier()

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setNumMultiplier ( FloatType  newNumMultiplier)
inlineconstexprnoexcept

Definition at line 118 of file ERational.hpp.

◆ setNumExponent()

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setNumExponent ( short int  newNumExponent)
inlineconstexprnoexcept

Definition at line 119 of file ERational.hpp.

◆ setDenominator() [1/2]

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setDenominator ( std::pair< FloatType, short int >  denominator)
inlineconstexprnoexcept

Definition at line 121 of file ERational.hpp.

◆ setDenominator() [2/2]

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setDenominator ( FloatType  newMultiplier,
short int  newExponent 
)
inlineconstexprnoexcept

Definition at line 122 of file ERational.hpp.

◆ setDenMultiplier()

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setDenMultiplier ( FloatType  newDenMultiplier)
inlineconstexprnoexcept

Definition at line 123 of file ERational.hpp.

◆ setDenExponent()

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::setDenExponent ( short int  newDenExponent)
inlineconstexprnoexcept

Definition at line 124 of file ERational.hpp.

◆ operator+()

template<typename FloatType >
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::operator+ ( const ERational< FloatType > &  anotherERational) const
constexpr

Sum operation between 2 experimental rationals.

Parameters
anotherERational
Returns
The sum in ERational

Definition at line 410 of file ERational.hpp.

◆ operator-()

template<typename FloatType >
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::operator- ( const ERational< FloatType > &  anotherERational) const
constexpr

Subtraction operation between 2 experimental rationals.

Parameters
anotherERational
Returns
The result in ERational

Definition at line 431 of file ERational.hpp.

◆ operator*()

template<typename FloatType >
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::operator* ( const ERational< FloatType > &  anotherERational) const
constexpr

Multiplication operation between 2 experimental rationals.

Parameters
anotherERational
Returns
The multiplication in ERational

Definition at line 452 of file ERational.hpp.

◆ operator/()

template<typename FloatType >
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::operator/ ( const ERational< FloatType > &  anotherERational) const
constexpr

Division operation between 2 experimental rationals.

Parameters
anotherERational
Returns
The result in ERational

Definition at line 466 of file ERational.hpp.

◆ operator==()

template<typename FloatType >
constexpr bool Arkulib::ERational< FloatType >::operator== ( const ERational< FloatType > &  anotherERational) const
inlineconstexpr

Comparison between 2 ERationals.

Parameters
anotherERational
Returns
True if the first erational is equal to the second

Definition at line 480 of file ERational.hpp.

◆ operator!=()

template<typename FloatType >
constexpr bool Arkulib::ERational< FloatType >::operator!= ( const ERational< FloatType > &  anotherERational) const
inlineconstexpr

Different comparison between 2 erationals.

Parameters
anotherERational
Returns
True if the first erational is different to the second

Definition at line 498 of file ERational.hpp.

◆ isNegative()

template<typename FloatType = double>
bool Arkulib::ERational< FloatType >::isNegative ( ) const
inlinenoexcept
Returns
True if the rational is negative

Definition at line 199 of file ERational.hpp.

◆ isInteger()

template<typename FloatType = double>
bool Arkulib::ERational< FloatType >::isInteger ( ) const
inlinenoexcept
Returns
True if the rational is an integer

Definition at line 207 of file ERational.hpp.

◆ isZero()

template<typename FloatType = double>
bool Arkulib::ERational< FloatType >::isZero ( ) const
inlinenoexcept
Returns
True if the rational is equal to zero

Definition at line 212 of file ERational.hpp.

◆ abs()

template<typename FloatType = double>
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::abs ( ) const
inlineconstexpr

Apply absolute value on the ERational.

Returns
The ERational in absolute value

Definition at line 222 of file ERational.hpp.

◆ inverse()

template<typename FloatType = double>
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::inverse ( ) const
inlineconstexpr

Get the inverse of an ERational.

Returns
The inversed ERational

Definition at line 233 of file ERational.hpp.

◆ simplify()

template<typename FloatType >
constexpr ERational< FloatType > Arkulib::ERational< FloatType >::simplify
constexprnoexcept

Simplify the Rational with GCD.

Definition at line 507 of file ERational.hpp.

◆ toRealNumber()

template<typename FloatType = double>
template<typename AnotherFloatType = double>
constexpr AnotherFloatType Arkulib::ERational< FloatType >::toRealNumber ( ) const
inlineconstexprnoexcept

Get an approximation floating point number of the experimental ratio.

Template Parameters
AnotherFloatType
Returns
A floating point number

Definition at line 252 of file ERational.hpp.

◆ toString()

template<typename FloatType = double>
std::string Arkulib::ERational< FloatType >::toString ( ) const
inlinenoexcept

Return ( numerator / denominator ) as a string.

Returns
std::string

Definition at line 262 of file ERational.hpp.

◆ transformToExperimental()

template<typename FloatType >
template<typename IntType >
constexpr void Arkulib::ERational< FloatType >::transformToExperimental ( IntType  numerator,
IntType  denominator 
)
constexprprivate

Set the parameters from a normal numerator and denominator.

Parameters
numerator
denominator

Definition at line 530 of file ERational.hpp.

◆ transformOperandToPair() [1/2]

template<typename FloatType = double>
template<typename IntType = int>
static constexpr std::pair< FloatType, short int > Arkulib::ERational< FloatType >::transformOperandToPair ( IntType  operand)
staticconstexprprivate

Transform a numerator/denominator into a pair.

Template Parameters
IntType
Parameters
operand
Returns

◆ verifyDenominator()

template<typename FloatType >
constexpr void Arkulib::ERational< FloatType >::verifyDenominator ( bool  checkIfDenominatorIsNull = true)
constexprprivate

Verify if the denominator is null or negative.

Parameters
checkIfDenominatorIsNull

Definition at line 546 of file ERational.hpp.

◆ verifyTemplateType()

template<typename FloatType = double>
constexpr void Arkulib::ERational< FloatType >::verifyTemplateType ( ) const
inlineconstexprprivate

Verify if the template is correct. Throw an exception if the template is an integral.

Definition at line 298 of file ERational.hpp.

◆ setAtSameNumeratorExponent()

template<typename FloatType >
constexpr void Arkulib::ERational< FloatType >::setAtSameNumeratorExponent ( ERational< FloatType > &  firstERational,
ERational< FloatType > &  secondERational 
) const
constexprprivate

Set firstERational and secondERational with the same numerator exponent.

Parameters
firstERational
secondERational

Definition at line 557 of file ERational.hpp.

◆ setAtSameDenominator()

template<typename FloatType >
constexpr void Arkulib::ERational< FloatType >::setAtSameDenominator ( ERational< FloatType > &  firstERational,
ERational< FloatType > &  secondERational 
) const
constexprprivate

Set firstERational and secondERational with the same denominator exponent.

Parameters
firstERational
secondERational

Definition at line 570 of file ERational.hpp.

◆ transformOperandToPair() [2/2]

template<typename FloatType = double>
template<typename IntType >
constexpr std::pair< FloatType, short > Arkulib::ERational< FloatType >::transformOperandToPair ( IntType  operand)
constexpr

Definition at line 537 of file ERational.hpp.

Member Data Documentation

◆ m_numerator

template<typename FloatType = double>
std::pair<FloatType, short int> Arkulib::ERational< FloatType >::m_numerator
private

Definition at line 326 of file ERational.hpp.

◆ m_denominator

template<typename FloatType = double>
std::pair<FloatType, short int> Arkulib::ERational< FloatType >::m_denominator
private

Definition at line 328 of file ERational.hpp.


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