Arkulib
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
Arkulib::Rational< IntType > Class Template Reference

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

#include <Rational.hpp>

Public Member Functions

constexpr Rational ()
 Instantiate an object without parameters. More...
 
constexpr Rational (IntType numerator, IntType denominator, bool willBeReduce=true, bool willDenominatorBeVerified=true)
 Create a rational from a numerator and a denominator. More...
 
template<typename FloatingType >
constexpr Rational (const FloatingType &nonRational)
 Create a rational from a floating number. More...
 
constexpr Rational (const Rational< IntType > &reference)=default
 Default copy constructor. More...
 
template<typename AnotherIntType >
constexpr Rational (Rational< AnotherIntType > &copiedRational)
 Copy constructor with another int type. More...
 
 ~Rational ()=default
 Default Destructor. More...
 
constexpr IntType getNumerator () const noexcept
 
constexpr IntType getDenominator () const noexcept
 
const IntType & operator[] (const size_t &id) const
 Getter with [] operator. More...
 
constexpr IntType getLargerOperand () const noexcept
 
constexpr IntType getLowerOperand () const noexcept
 
constexpr void setNumerator (IntType numerator)
 
constexpr void setDenominator (IntType denominator)
 
IntType & operator[] (const size_t &id)
 Setter with [] operator. Example: rational[0] = 1 and rational[1] = 2 //// total => (1/2) More...
 
bool isNegative () const noexcept
 
bool isInteger () const noexcept
 
bool isZero () const noexcept
 
constexpr Rational< IntType > operator+ (const Rational< IntType > &anotherRational) const
 Addition operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator+ (const NonRationalType &nonRational) const
 Addition operation between a rational and another type. Example: Rational + int. More...
 
constexpr Rational< IntType > operator- (const Rational< IntType > &anotherRational) const
 Subtraction operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator- (const NonRationalType &nonRational) const
 Subtraction operation between a rational and another type. Example: Rational - int. More...
 
constexpr Rational< IntType > operator* (const Rational< IntType > &anotherRational) const
 Multiplication operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator* (const NonRationalType &nonRational) const
 Multiplication operation between a rational and another type. Example: Rational * int. More...
 
constexpr Rational< IntType > operator/ (const Rational< IntType > &anotherRational) const
 Division operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator/ (const NonRationalType &nonRational) const
 Division operation between a rational and another type. Example: Rational / int. More...
 
constexpr bool operator== (const Rational< IntType > &anotherRational) const
 Comparison between 2 rationals. More...
 
template<typename NonRationalType >
constexpr bool operator== (const NonRationalType &nonRational) const
 Comparison between a rational and a non-rational. Example: Rational == int. More...
 
constexpr bool operator!= (const Rational< IntType > &anotherRational) const
 Different comparison between 2 rationals. More...
 
template<typename NonRationalType >
constexpr bool operator!= (const NonRationalType &nonRational) const
 Different comparison between a rational and a non-rational. Example: Rational != int. More...
 
constexpr bool operator< (const Rational< IntType > &anotherRational) const
 < Comparison between 2 rationals More...
 
template<typename NonRationalType >
constexpr bool operator< (const NonRationalType &nonRational) const
 < Comparison between a rational and a non-rational. Example: Rational < int More...
 
constexpr bool operator<= (const Rational< IntType > &anotherRational) const
 <= Comparison between 2 rationals More...
 
template<typename NonRationalType >
constexpr bool operator<= (const NonRationalType &nonRational) const
 <= Comparison between a rational and a non-rational. Example: Rational <= int More...
 
constexpr bool operator> (const Rational< IntType > &anotherRational) const
 > Comparison between 2 rationals More...
 
template<typename NonRationalType >
constexpr bool operator> (const NonRationalType &nonRational) const
 > Comparison between a rational and a non-rational. Example: Rational > int More...
 
constexpr bool operator>= (const Rational< IntType > &anotherRational) const
 >= Comparison between 2 rationals More...
 
template<typename NonRationalType >
constexpr bool operator>= (const NonRationalType &nonRational) const
 >= Comparison between a rational and a non-rational. Example: Rational >= int More...
 
constexpr Rational< IntType > operator+= (const Rational< IntType > &anotherRational)
 Addition assignment operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator+= (const NonRationalType &nonRational)
 Addition assignment operation between a rational and another type. Example: Rational += int. More...
 
constexpr void operator++ ()
 Increment operator. More...
 
constexpr Rational< IntType > operator-= (const Rational< IntType > &anotherRational)
 
template<typename NonRationalType >
constexpr Rational< IntType > operator-= (const NonRationalType &nonRational)
 Subtraction assignment operation between a rational and another type. Example: Rational - int. More...
 
constexpr void operator-- ()
 Decrement operator. More...
 
constexpr Rational< IntType > operator*= (const Rational< IntType > &anotherRational)
 Multiplication assignment operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator*= (const NonRationalType &nonRational)
 Multiplication assignment operation between a rational and another type. Example: Rational * int. More...
 
constexpr Rational< IntType > operator/= (const Rational< IntType > &anotherRational)
 Division assignment operation between 2 rationals. More...
 
template<typename NonRationalType >
constexpr Rational< IntType > operator/= (const NonRationalType &nonRational)
 Multiplication assignment operation between a rational and another type. Example: Rational * int. More...
 
constexpr Rational< IntType > inverse () const
 Inverse a rational : a / b into b / a. More...
 
constexpr Rational< IntType > sqrt () const
 Give the square root of a rational. More...
 
constexpr Rational< IntType > cos () const
 Give the cosine of a rational. More...
 
constexpr Rational< IntType > exp () const
 Give the exponential of a rational. More...
 
template<typename FloatingType >
constexpr Rational< IntType > pow (const FloatingType &k) const
 Give the power of a rational. More...
 
constexpr Rational< IntType > abs () const
 Give the abs of a rational. More...
 
constexpr Rational< IntType > simplify () const noexcept
 Simplify the Rational with GCD (called in constructor) More...
 
constexpr Rational< IntType > toApproximation (unsigned int digitsKept=Constant::DEFAULT_KEPT_DIGITS_APPROXIMATE) const
 Get an approximation of a given Rational. We assume that you don't ask a bigger precision that you don't have. More...
 
constexpr IntType toInteger () const noexcept
 Get the integer part of the ratio. More...
 
template<typename FloatingType = float>
constexpr FloatingType toRealNumber () const noexcept
 Get an approximation floating point number of the ratio. More...
 
std::string toString () const noexcept
 Return ( numerator / denominator ) as a string. More...
 
template<typename FloatingType >
Rational< IntType > constexpr fromFloatingPoint (const FloatingType floatingRatio, size_t iter)
 

Static Public Member Functions

static constexpr Rational< IntType > min (Rational< IntType > rational1, Rational< IntType > rational2) noexcept
 Return the minimum between two rationals. More...
 
template<typename ... Args>
static constexpr Rational< IntType > min (Rational< IntType > rational, Args... args) noexcept
 Variadic: Return the minimum between various rationals. More...
 
static constexpr Rational< IntType > max (Rational< IntType > rational1, Rational< IntType > rational2) noexcept
 Return the maximum between two rationals. More...
 
template<typename ... Args>
static constexpr Rational< IntType > max (Rational< IntType > rational, Args... args) noexcept
 Variadic: Return the maximum between various rationals. More...
 
static constexpr Rational< IntType > Zero () noexcept
 Return zero in Rational Type. More...
 
static constexpr Rational< IntType > One () noexcept
 Return one in Rational Type. More...
 
static constexpr Rational< IntType > Pi () noexcept
 Return Pi in Rational Type. More...
 
static constexpr Rational< IntType > Infinite () noexcept
 Return an approximation of +infinite in Rational Type. More...
 
template<typename FloatingType = double>
static constexpr Rational< IntType > fromFloatingPoint (FloatingType floatingRatio, size_t iter=Constant::DEFAULT_ITERATIONS_FROM_FP)
 A method who automatically set numerator and denominator to approach the float parameter. More...
 
constexpr static void print (const Rational< IntType > rational) noexcept
 Print the value of a rational. More...
 
template<typename... Args>
constexpr static void print (const Rational< IntType > rational, Args... args) noexcept
 Variadic: Print the values of various rationals. More...
 

Protected Member Functions

constexpr void verifyTemplateType () const
 Verify if the template is correct. Throw an exception if the template is a floating point. More...
 
constexpr void verifyDenominator (IntType denominator, bool checkIfDenominatorIsNull=true)
 Verify if the denominator is null or negative. More...
 
template<typename AnotherIntType >
constexpr void verifyNumberLargeness (Rational< AnotherIntType > &anotherRational) const
 Verify if the operands are superior to the limit of IntType. More...
 

Static Protected Member Functions

static constexpr Rational< IntType > checkForOverflowThenReturn (const long long int numerator, const long long int denominator)
 Check for overflow before returning a value. More...
 

Protected Attributes

IntType m_numerator
 Rational's numerator. More...
 
IntType m_denominator
 Rational's denominator. More...
 

Friends

template<typename NonRationalType >
constexpr friend Rational< IntType > operator+ (const NonRationalType nonRational, const Rational< IntType > &rational)
 Addition operation between a non-rational and a rational. Example: int + Rational. More...
 
template<typename NonRationalType >
constexpr friend Rational< IntType > operator- (const NonRationalType nonRational, const Rational< IntType > &rational)
 Subtraction operation between a non-rational and a rational. Example: int - Rational. More...
 
constexpr friend Rational operator- (const Rational &rational)
 Unary operator, allow to do -Rational. More...
 
template<typename NonRationalType >
constexpr friend Rational< IntType > operator* (const NonRationalType nonRational, const Rational< IntType > &rational)
 Multiplication operation between a non-rational and a rational. Example: int * Rational. More...
 
template<typename NonRationalType >
constexpr friend Rational< IntType > operator/ (const NonRationalType nonRational, const Rational< IntType > &rational)
 Division operation between a non-rational and a rational. Example: int / Rational. More...
 
template<typename NonRationalType >
constexpr friend bool operator== (const NonRationalType nonRational, const Rational< IntType > &rational)
 Comparison between a non-rational and a rational. Example: int == Rational. More...
 
template<typename NonRationalType >
constexpr friend bool operator!= (const NonRationalType nonRational, const Rational< IntType > &rational)
 Different comparison between a non-rational and a rational. Example: int != Rational. More...
 
template<typename NonRationalType >
constexpr friend bool operator< (const NonRationalType nonRational, const Rational< IntType > &rational)
 < Comparison between a non-rational and a rational. Example: int < Rational More...
 
template<typename NonRationalType >
constexpr friend bool operator<= (const NonRationalType nonRational, const Rational< IntType > &rational)
 <= Comparison between a non-rational and a rational. Example: int <= Rational More...
 
template<typename NonRationalType >
constexpr friend bool operator> (const NonRationalType nonRational, const Rational< IntType > &rational)
 < Comparison between a non-rational and a rational. Example: int > Rational More...
 
template<typename NonRationalType >
constexpr friend bool operator>= (const NonRationalType nonRational, const Rational< IntType > &rational)
 >= Comparison between a non-rational and a rational. Example: int >= Rational More...
 

Detailed Description

template<typename IntType = int>
class Arkulib::Rational< IntType >

This class can be used to express rationals.

Template Parameters
IntType

Definition at line 27 of file Rational.hpp.

Constructor & Destructor Documentation

◆ Rational() [1/5]

template<typename IntType = int>
constexpr Arkulib::Rational< IntType >::Rational ( )
inlineconstexpr

Instantiate an object without parameters.

Definition at line 38 of file Rational.hpp.

◆ Rational() [2/5]

template<typename IntType >
constexpr Arkulib::Rational< IntType >::Rational ( IntType  numerator,
IntType  denominator,
bool  willBeReduce = true,
bool  willDenominatorBeVerified = true 
)
constexpr

Create a rational from a numerator and a denominator.

Parameters
numerator
denominator
willBeReduce
willDenominatorBeVerified

Definition at line 942 of file Rational.hpp.

◆ Rational() [3/5]

template<typename IntType >
template<typename FloatingType >
constexpr Arkulib::Rational< IntType >::Rational ( const FloatingType &  nonRational)
explicitconstexpr

Create a rational from a floating number.

Template Parameters
FloatingType
Parameters
nonRational

Definition at line 958 of file Rational.hpp.

◆ Rational() [4/5]

template<typename IntType = int>
constexpr Arkulib::Rational< IntType >::Rational ( const Rational< IntType > &  reference)
inlineconstexprdefault

Default copy constructor.

Parameters
reference

◆ Rational() [5/5]

template<typename IntType >
template<typename AnotherIntType >
constexpr Arkulib::Rational< IntType >::Rational ( Rational< AnotherIntType > &  copiedRational)
explicitconstexpr

Copy constructor with another int type.

Template Parameters
AnotherIntType
Parameters
copiedRational

Definition at line 981 of file Rational.hpp.

◆ ~Rational()

template<typename IntType = int>
Arkulib::Rational< IntType >::~Rational ( )
inlinedefault

Default Destructor.

Member Function Documentation

◆ getNumerator()

template<typename IntType = int>
constexpr IntType Arkulib::Rational< IntType >::getNumerator ( ) const
inlineconstexprnoexcept

Definition at line 85 of file Rational.hpp.

◆ getDenominator()

template<typename IntType = int>
constexpr IntType Arkulib::Rational< IntType >::getDenominator ( ) const
inlineconstexprnoexcept

Definition at line 87 of file Rational.hpp.

◆ operator[]() [1/2]

template<typename IntType >
const IntType & Arkulib::Rational< IntType >::operator[] ( const size_t &  id) const
inline

Getter with [] operator.

Parameters
id
Returns
If id == 0 => return numerator; if id == 1 => return denominator

Definition at line 991 of file Rational.hpp.

◆ getLargerOperand()

template<typename IntType = int>
constexpr IntType Arkulib::Rational< IntType >::getLargerOperand ( ) const
inlineconstexprnoexcept
Returns
The numerator if numerator > denominator. Return denominator else.

Definition at line 99 of file Rational.hpp.

◆ getLowerOperand()

template<typename IntType = int>
constexpr IntType Arkulib::Rational< IntType >::getLowerOperand ( ) const
inlineconstexprnoexcept
Returns
The denominator if numerator > denominator. Return numerator else.

Definition at line 106 of file Rational.hpp.

◆ setNumerator()

template<typename IntType = int>
constexpr void Arkulib::Rational< IntType >::setNumerator ( IntType  numerator)
inlineconstexpr

Definition at line 114 of file Rational.hpp.

◆ setDenominator()

template<typename IntType = int>
constexpr void Arkulib::Rational< IntType >::setDenominator ( IntType  denominator)
inlineconstexpr

Definition at line 116 of file Rational.hpp.

◆ operator[]() [2/2]

template<typename IntType >
IntType & Arkulib::Rational< IntType >::operator[] ( const size_t &  id)
inline

Setter with [] operator. Example: rational[0] = 1 and rational[1] = 2 //// total => (1/2)

Parameters
id

Definition at line 998 of file Rational.hpp.

◆ isNegative()

template<typename IntType = int>
bool Arkulib::Rational< IntType >::isNegative ( ) const
inlinenoexcept
Returns
True if the rational is negative

Definition at line 134 of file Rational.hpp.

◆ isInteger()

template<typename IntType = int>
bool Arkulib::Rational< IntType >::isInteger ( ) const
inlinenoexcept
Returns
True if the rational is an integer

Definition at line 139 of file Rational.hpp.

◆ isZero()

template<typename IntType = int>
bool Arkulib::Rational< IntType >::isZero ( ) const
inlinenoexcept
Returns
True if the rational is equal to zero

Definition at line 144 of file Rational.hpp.

◆ operator+() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator+ ( const Rational< IntType > &  anotherRational) const
constexpr

Addition operation between 2 rationals.

Parameters
anotherRational
Returns
The sum in Rational

Definition at line 1009 of file Rational.hpp.

◆ operator+() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator+ ( const NonRationalType &  nonRational) const
inlineconstexpr

Addition operation between a rational and another type. Example: Rational + int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The sum in Rational

Definition at line 164 of file Rational.hpp.

◆ operator-() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator- ( const Rational< IntType > &  anotherRational) const
constexpr

Subtraction operation between 2 rationals.

Parameters
anotherRational
Returns
The subtraction in Rational

Definition at line 1021 of file Rational.hpp.

◆ operator-() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator- ( const NonRationalType &  nonRational) const
inlineconstexpr

Subtraction operation between a rational and another type. Example: Rational - int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The subtraction in Rational

Definition at line 201 of file Rational.hpp.

◆ operator*() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator* ( const Rational< IntType > &  anotherRational) const
constexpr

Multiplication operation between 2 rationals.

Parameters
anotherRational
Returns
The multiplication in Rational

Definition at line 1033 of file Rational.hpp.

◆ operator*() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator* ( const NonRationalType &  nonRational) const
inlineconstexpr

Multiplication operation between a rational and another type. Example: Rational * int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The multiplication in Rational

Definition at line 247 of file Rational.hpp.

◆ operator/() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator/ ( const Rational< IntType > &  anotherRational) const
constexpr

Division operation between 2 rationals.

Parameters
anotherRational
Returns
The division in Rational

Definition at line 1045 of file Rational.hpp.

◆ operator/() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator/ ( const NonRationalType &  nonRational) const
inlineconstexpr

Division operation between a rational and another type. Example: Rational / int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The division in Rational

Definition at line 284 of file Rational.hpp.

◆ operator==() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator== ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

Comparison between 2 rationals.

Parameters
anotherRational
Returns
True if the first rational is equal to the second

Definition at line 312 of file Rational.hpp.

◆ operator==() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator== ( const NonRationalType &  nonRational) const
inlineconstexpr

Comparison between a rational and a non-rational. Example: Rational == int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is equal to the second operand

Definition at line 327 of file Rational.hpp.

◆ operator!=() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator!= ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

Different comparison between 2 rationals.

Parameters
anotherRational
Returns
True if the first rational is different to the second

Definition at line 355 of file Rational.hpp.

◆ operator!=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator!= ( const NonRationalType &  nonRational) const
inlineconstexpr

Different comparison between a rational and a non-rational. Example: Rational != int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is different to the second operand

Definition at line 370 of file Rational.hpp.

◆ operator<() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator< ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

< Comparison between 2 rationals

Parameters
anotherRational
Returns
True if the first rational is inferior to the second

Definition at line 398 of file Rational.hpp.

◆ operator<() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator< ( const NonRationalType &  nonRational) const
inlineconstexpr

< Comparison between a rational and a non-rational. Example: Rational < int

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is inferior to the second operand

Definition at line 409 of file Rational.hpp.

◆ operator<=() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator<= ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

<= Comparison between 2 rationals

Parameters
anotherRational
Returns
True if the first rational is inferior to the second

Definition at line 435 of file Rational.hpp.

◆ operator<=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator<= ( const NonRationalType &  nonRational) const
inlineconstexpr

<= Comparison between a rational and a non-rational. Example: Rational <= int

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is inferior to the second operand

Definition at line 446 of file Rational.hpp.

◆ operator>() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator> ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

> Comparison between 2 rationals

Parameters
anotherRational
Returns
True if the first rational is inferior to the second

Definition at line 474 of file Rational.hpp.

◆ operator>() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator> ( const NonRationalType &  nonRational) const
inlineconstexpr

> Comparison between a rational and a non-rational. Example: Rational > int

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is inferior to the second operand

Definition at line 485 of file Rational.hpp.

◆ operator>=() [1/2]

template<typename IntType = int>
constexpr bool Arkulib::Rational< IntType >::operator>= ( const Rational< IntType > &  anotherRational) const
inlineconstexpr

>= Comparison between 2 rationals

Parameters
anotherRational
Returns
True if the first rational is inferior to the second

Definition at line 513 of file Rational.hpp.

◆ operator>=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr bool Arkulib::Rational< IntType >::operator>= ( const NonRationalType &  nonRational) const
inlineconstexpr

>= Comparison between a rational and a non-rational. Example: Rational >= int

Template Parameters
NonRationalType
Parameters
nonRational
Returns
True if the rational is inferior to the second operand

Definition at line 524 of file Rational.hpp.

◆ operator+=() [1/2]

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator+= ( const Rational< IntType > &  anotherRational)
inlineconstexpr

Addition assignment operation between 2 rationals.

Parameters
anotherRational
Returns
The sum assignment in Rational

Definition at line 552 of file Rational.hpp.

◆ operator+=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator+= ( const NonRationalType &  nonRational)
inlineconstexpr

Addition assignment operation between a rational and another type. Example: Rational += int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The sum assigment in Rational

Definition at line 564 of file Rational.hpp.

◆ operator++()

template<typename IntType = int>
constexpr void Arkulib::Rational< IntType >::operator++ ( )
inlineconstexpr

Increment operator.

Definition at line 576 of file Rational.hpp.

◆ operator-=() [1/2]

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator-= ( const Rational< IntType > &  anotherRational)
inlineconstexpr
Parameters
anotherRational
Returns
The subtraction in Rational

Definition at line 587 of file Rational.hpp.

◆ operator-=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator-= ( const NonRationalType &  nonRational)
inlineconstexpr

Subtraction assignment operation between a rational and another type. Example: Rational - int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The subtraction assigment in Rational

Definition at line 599 of file Rational.hpp.

◆ operator--()

template<typename IntType = int>
constexpr void Arkulib::Rational< IntType >::operator-- ( )
inlineconstexpr

Decrement operator.

Definition at line 611 of file Rational.hpp.

◆ operator*=() [1/2]

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator*= ( const Rational< IntType > &  anotherRational)
inlineconstexpr

Multiplication assignment operation between 2 rationals.

Parameters
anotherRational
Returns
The multiplication in Rational

Definition at line 622 of file Rational.hpp.

◆ operator*=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator*= ( const NonRationalType &  nonRational)
inlineconstexpr

Multiplication assignment operation between a rational and another type. Example: Rational * int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The multiplication assigment in Rational

Definition at line 634 of file Rational.hpp.

◆ operator/=() [1/2]

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator/= ( const Rational< IntType > &  anotherRational)
inlineconstexpr

Division assignment operation between 2 rationals.

Parameters
anotherRational
Returns
The division in Rational

Definition at line 648 of file Rational.hpp.

◆ operator/=() [2/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::operator/= ( const NonRationalType &  nonRational)
inlineconstexpr

Multiplication assignment operation between a rational and another type. Example: Rational * int.

Template Parameters
NonRationalType
Parameters
nonRational
Returns
The multiplication assigment in Rational

Definition at line 660 of file Rational.hpp.

◆ inverse()

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::inverse ( ) const
inlineconstexpr

Inverse a rational : a / b into b / a.

Returns
The inverted Rational

Definition at line 674 of file Rational.hpp.

◆ sqrt()

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::sqrt
constexpr

Give the square root of a rational.

Returns
The square root as a Rational

Definition at line 1057 of file Rational.hpp.

◆ cos()

template<typename IntType >
Rational< IntType > constexpr Arkulib::Rational< IntType >::cos
constexpr

Give the cosine of a rational.

Returns
The cosine as a Rational

Definition at line 1065 of file Rational.hpp.

◆ exp()

template<typename IntType >
Rational< IntType > constexpr Arkulib::Rational< IntType >::exp
constexpr

Give the exponential of a rational.

Returns
The exponential as a Rational

Definition at line 1072 of file Rational.hpp.

◆ pow()

template<typename IntType >
template<typename FloatingType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::pow ( const FloatingType &  k) const
constexpr

Give the power of a rational.

Returns
The power as a Rational

Definition at line 1080 of file Rational.hpp.

◆ abs()

template<typename IntType = int>
constexpr Rational< IntType > Arkulib::Rational< IntType >::abs ( ) const
inlineconstexpr

Give the abs of a rational.

Returns
The Rational in absolute value

Definition at line 708 of file Rational.hpp.

◆ simplify()

template<typename IntType >
Rational< IntType > constexpr Arkulib::Rational< IntType >::simplify
constexprnoexcept

Simplify the Rational with GCD (called in constructor)

Definition at line 1087 of file Rational.hpp.

◆ min() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::min ( Rational< IntType >  rational1,
Rational< IntType >  rational2 
)
staticconstexprnoexcept

Return the minimum between two rationals.

Parameters
rational1
rational2
Returns

Definition at line 1103 of file Rational.hpp.

◆ min() [2/2]

template<typename IntType >
template<typename... Args>
constexpr Rational< IntType > Arkulib::Rational< IntType >::min ( Rational< IntType >  rational,
Args...  args 
)
staticconstexprnoexcept

Variadic: Return the minimum between various rationals.

Template Parameters
Args
Parameters
rational
args
Returns

Definition at line 1112 of file Rational.hpp.

◆ max() [1/2]

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::max ( Rational< IntType >  rational1,
Rational< IntType >  rational2 
)
staticconstexprnoexcept

Return the maximum between two rationals.

Parameters
rational1
rational2
Returns

Definition at line 1124 of file Rational.hpp.

◆ max() [2/2]

template<typename IntType >
template<typename... Args>
constexpr Rational< IntType > Arkulib::Rational< IntType >::max ( Rational< IntType >  rational,
Args...  args 
)
staticconstexprnoexcept

Variadic: Return the maximum between various rationals.

Template Parameters
Args
Parameters
rational
args
Returns

Definition at line 1133 of file Rational.hpp.

◆ Zero()

template<typename IntType = int>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::Zero ( )
inlinestaticconstexprnoexcept

Return zero in Rational Type.

Returns
Rational with 0 as numerator and 1 as denominator

Definition at line 781 of file Rational.hpp.

◆ One()

template<typename IntType = int>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::One ( )
inlinestaticconstexprnoexcept

Return one in Rational Type.

Returns
Rational with 1 as numerator and 1 as denominator

Definition at line 787 of file Rational.hpp.

◆ Pi()

template<typename IntType = int>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::Pi ( )
inlinestaticconstexprnoexcept

Return Pi in Rational Type.

Returns
An approximation of Pi

Definition at line 793 of file Rational.hpp.

◆ Infinite()

template<typename IntType = int>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::Infinite ( )
inlinestaticconstexprnoexcept

Return an approximation of +infinite in Rational Type.

Returns
1 as numerator and 0 as denominator

Definition at line 799 of file Rational.hpp.

◆ toApproximation()

template<typename IntType >
constexpr Rational< IntType > Arkulib::Rational< IntType >::toApproximation ( unsigned int  digitsKept = Constant::DEFAULT_KEPT_DIGITS_APPROXIMATE) const
inlineconstexpr

Get an approximation of a given Rational. We assume that you don't ask a bigger precision that you don't have.

Parameters
digitsKept
Returns
The approximated Ratio

Definition at line 1145 of file Rational.hpp.

◆ toInteger()

template<typename IntType = int>
constexpr IntType Arkulib::Rational< IntType >::toInteger ( ) const
inlineconstexprnoexcept

Get the integer part of the ratio.

Returns
An int (type IntType)

Definition at line 818 of file Rational.hpp.

◆ toRealNumber()

template<typename IntType = int>
template<typename FloatingType = float>
constexpr FloatingType Arkulib::Rational< IntType >::toRealNumber ( ) const
inlineconstexprnoexcept

Get an approximation floating point number of the ratio.

Template Parameters
FloatingType
Returns
A floating point number (type FloatingType)

Definition at line 829 of file Rational.hpp.

◆ toString()

template<typename IntType = int>
std::string Arkulib::Rational< IntType >::toString ( ) const
inlinenoexcept

Return ( numerator / denominator ) as a string.

Returns
std::string

Definition at line 838 of file Rational.hpp.

◆ fromFloatingPoint() [1/2]

template<typename IntType = int>
template<typename FloatingType = double>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::fromFloatingPoint ( FloatingType  floatingRatio,
size_t  iter = Constant::DEFAULT_ITERATIONS_FROM_FP 
)
staticconstexpr

A method who automatically set numerator and denominator to approach the float parameter.

Template Parameters
FloatingType
Parameters
floatingRatio
iter
Returns
The rational wanted

◆ print() [1/2]

template<typename IntType = int>
constexpr static void Arkulib::Rational< IntType >::print ( const Rational< IntType >  rational)
inlinestaticconstexprnoexcept

Print the value of a rational.

Template Parameters
IntType
Parameters
rational

Definition at line 860 of file Rational.hpp.

◆ print() [2/2]

template<typename IntType = int>
template<typename... Args>
constexpr static void Arkulib::Rational< IntType >::print ( const Rational< IntType >  rational,
Args...  args 
)
inlinestaticconstexprnoexcept

Variadic: Print the values of various rationals.

Template Parameters
IntType
Args
Parameters
rational
args

Definition at line 872 of file Rational.hpp.

◆ verifyTemplateType()

template<typename IntType = int>
constexpr void Arkulib::Rational< IntType >::verifyTemplateType ( ) const
inlineconstexprprotected

Verify if the template is correct. Throw an exception if the template is a floating point.

Definition at line 894 of file Rational.hpp.

◆ verifyDenominator()

template<typename IntType >
constexpr void Arkulib::Rational< IntType >::verifyDenominator ( IntType  denominator,
bool  checkIfDenominatorIsNull = true 
)
constexprprotected

Verify if the denominator is null or negative.

Parameters
denominator
checkIfDenominatorIsNull

Definition at line 1195 of file Rational.hpp.

◆ verifyNumberLargeness()

template<typename IntType >
template<typename AnotherIntType >
constexpr void Arkulib::Rational< IntType >::verifyNumberLargeness ( Rational< AnotherIntType > &  anotherRational) const
constexprprotected

Verify if the operands are superior to the limit of IntType.

Template Parameters
AnotherIntType
Parameters
anotherRational

Definition at line 1183 of file Rational.hpp.

◆ checkForOverflowThenReturn()

template<typename IntType = int>
static constexpr Rational< IntType > Arkulib::Rational< IntType >::checkForOverflowThenReturn ( const long long int  numerator,
const long long int  denominator 
)
inlinestaticconstexprprotected

Check for overflow before returning a value.

Parameters
numerator
denominator
Returns
The rational if there is no error. If these is an overflow error, it'll throw an exception

Definition at line 919 of file Rational.hpp.

◆ fromFloatingPoint() [2/2]

template<typename IntType = int>
template<typename FloatingType >
Rational< IntType > constexpr Arkulib::Rational< IntType >::fromFloatingPoint ( const FloatingType  floatingRatio,
size_t  iter 
)
constexpr

Definition at line 1152 of file Rational.hpp.

Friends And Related Function Documentation

◆ operator+

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend Rational< IntType > operator+ ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Addition operation between a non-rational and a rational. Example: int + Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
The sum in Rational

Definition at line 176 of file Rational.hpp.

◆ operator- [1/2]

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend Rational< IntType > operator- ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Subtraction operation between a non-rational and a rational. Example: int - Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
The subtraction in Rational

Definition at line 213 of file Rational.hpp.

◆ operator- [2/2]

template<typename IntType = int>
constexpr friend Rational operator- ( const Rational< IntType > &  rational)
friend

Unary operator, allow to do -Rational.

Parameters
rational
Returns
The rational in negative

Definition at line 225 of file Rational.hpp.

◆ operator*

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend Rational< IntType > operator* ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Multiplication operation between a non-rational and a rational. Example: int * Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
The multiplication in Rational

Definition at line 259 of file Rational.hpp.

◆ operator/

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend Rational< IntType > operator/ ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Division operation between a non-rational and a rational. Example: int / Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
The division in Rational

Definition at line 296 of file Rational.hpp.

◆ operator==

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator== ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Comparison between a non-rational and a rational. Example: int == Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is equal to the rational

Definition at line 339 of file Rational.hpp.

◆ operator!=

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator!= ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

Different comparison between a non-rational and a rational. Example: int != Rational.

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is different to the rational

Definition at line 382 of file Rational.hpp.

◆ operator<

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator< ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

< Comparison between a non-rational and a rational. Example: int < Rational

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is inferior to the rational

Definition at line 419 of file Rational.hpp.

◆ operator<=

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator<= ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

<= Comparison between a non-rational and a rational. Example: int <= Rational

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is inferior to the rational

Definition at line 458 of file Rational.hpp.

◆ operator>

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator> ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

< Comparison between a non-rational and a rational. Example: int > Rational

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is superior to the rational

Definition at line 497 of file Rational.hpp.

◆ operator>=

template<typename IntType = int>
template<typename NonRationalType >
constexpr friend bool operator>= ( const NonRationalType  nonRational,
const Rational< IntType > &  rational 
)
friend

>= Comparison between a non-rational and a rational. Example: int >= Rational

Template Parameters
NonRationalType
Parameters
nonRational
rational
Returns
True if the non-rational is superior to the rational

Definition at line 536 of file Rational.hpp.

Member Data Documentation

◆ m_numerator

template<typename IntType = int>
IntType Arkulib::Rational< IntType >::m_numerator
protected

Rational's numerator.

Definition at line 883 of file Rational.hpp.

◆ m_denominator

template<typename IntType = int>
IntType Arkulib::Rational< IntType >::m_denominator
protected

Rational's denominator.

Definition at line 885 of file Rational.hpp.


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