Arkulib
|
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... | |
This class can be used to express rationals.
IntType |
Definition at line 27 of file Rational.hpp.
|
inlineconstexpr |
Instantiate an object without parameters.
Definition at line 38 of file Rational.hpp.
|
constexpr |
Create a rational from a numerator and a denominator.
numerator | |
denominator | |
willBeReduce | |
willDenominatorBeVerified |
Definition at line 942 of file Rational.hpp.
|
explicitconstexpr |
Create a rational from a floating number.
FloatingType |
nonRational |
Definition at line 958 of file Rational.hpp.
|
inlineconstexprdefault |
Default copy constructor.
reference |
|
explicitconstexpr |
Copy constructor with another int type.
AnotherIntType |
copiedRational |
Definition at line 981 of file Rational.hpp.
|
inlinedefault |
Default Destructor.
|
inlineconstexprnoexcept |
Definition at line 85 of file Rational.hpp.
|
inlineconstexprnoexcept |
Definition at line 87 of file Rational.hpp.
|
inline |
Getter with [] operator.
id |
Definition at line 991 of file Rational.hpp.
|
inlineconstexprnoexcept |
Definition at line 99 of file Rational.hpp.
|
inlineconstexprnoexcept |
Definition at line 106 of file Rational.hpp.
|
inlineconstexpr |
Definition at line 114 of file Rational.hpp.
|
inlineconstexpr |
Definition at line 116 of file Rational.hpp.
|
inline |
Setter with [] operator. Example: rational[0] = 1 and rational[1] = 2 //// total => (1/2)
id |
Definition at line 998 of file Rational.hpp.
|
inlinenoexcept |
Definition at line 134 of file Rational.hpp.
|
inlinenoexcept |
Definition at line 139 of file Rational.hpp.
|
inlinenoexcept |
Definition at line 144 of file Rational.hpp.
|
constexpr |
Addition operation between 2 rationals.
anotherRational |
Definition at line 1009 of file Rational.hpp.
|
inlineconstexpr |
Addition operation between a rational and another type. Example: Rational + int.
NonRationalType |
nonRational |
Definition at line 164 of file Rational.hpp.
|
constexpr |
Subtraction operation between 2 rationals.
anotherRational |
Definition at line 1021 of file Rational.hpp.
|
inlineconstexpr |
Subtraction operation between a rational and another type. Example: Rational - int.
NonRationalType |
nonRational |
Definition at line 201 of file Rational.hpp.
|
constexpr |
Multiplication operation between 2 rationals.
anotherRational |
Definition at line 1033 of file Rational.hpp.
|
inlineconstexpr |
Multiplication operation between a rational and another type. Example: Rational * int.
NonRationalType |
nonRational |
Definition at line 247 of file Rational.hpp.
|
constexpr |
Division operation between 2 rationals.
anotherRational |
Definition at line 1045 of file Rational.hpp.
|
inlineconstexpr |
Division operation between a rational and another type. Example: Rational / int.
NonRationalType |
nonRational |
Definition at line 284 of file Rational.hpp.
|
inlineconstexpr |
Comparison between 2 rationals.
anotherRational |
Definition at line 312 of file Rational.hpp.
|
inlineconstexpr |
Comparison between a rational and a non-rational. Example: Rational == int.
NonRationalType |
nonRational |
Definition at line 327 of file Rational.hpp.
|
inlineconstexpr |
Different comparison between 2 rationals.
anotherRational |
Definition at line 355 of file Rational.hpp.
|
inlineconstexpr |
Different comparison between a rational and a non-rational. Example: Rational != int.
NonRationalType |
nonRational |
Definition at line 370 of file Rational.hpp.
|
inlineconstexpr |
< Comparison between 2 rationals
anotherRational |
Definition at line 398 of file Rational.hpp.
|
inlineconstexpr |
< Comparison between a rational and a non-rational. Example: Rational < int
NonRationalType |
nonRational |
Definition at line 409 of file Rational.hpp.
|
inlineconstexpr |
<= Comparison between 2 rationals
anotherRational |
Definition at line 435 of file Rational.hpp.
|
inlineconstexpr |
<= Comparison between a rational and a non-rational. Example: Rational <= int
NonRationalType |
nonRational |
Definition at line 446 of file Rational.hpp.
|
inlineconstexpr |
> Comparison between 2 rationals
anotherRational |
Definition at line 474 of file Rational.hpp.
|
inlineconstexpr |
> Comparison between a rational and a non-rational. Example: Rational > int
NonRationalType |
nonRational |
Definition at line 485 of file Rational.hpp.
|
inlineconstexpr |
>= Comparison between 2 rationals
anotherRational |
Definition at line 513 of file Rational.hpp.
|
inlineconstexpr |
>= Comparison between a rational and a non-rational. Example: Rational >= int
NonRationalType |
nonRational |
Definition at line 524 of file Rational.hpp.
|
inlineconstexpr |
Addition assignment operation between 2 rationals.
anotherRational |
Definition at line 552 of file Rational.hpp.
|
inlineconstexpr |
Addition assignment operation between a rational and another type. Example: Rational += int.
NonRationalType |
nonRational |
Definition at line 564 of file Rational.hpp.
|
inlineconstexpr |
Increment operator.
Definition at line 576 of file Rational.hpp.
|
inlineconstexpr |
anotherRational |
Definition at line 587 of file Rational.hpp.
|
inlineconstexpr |
Subtraction assignment operation between a rational and another type. Example: Rational - int.
NonRationalType |
nonRational |
Definition at line 599 of file Rational.hpp.
|
inlineconstexpr |
Decrement operator.
Definition at line 611 of file Rational.hpp.
|
inlineconstexpr |
Multiplication assignment operation between 2 rationals.
anotherRational |
Definition at line 622 of file Rational.hpp.
|
inlineconstexpr |
Multiplication assignment operation between a rational and another type. Example: Rational * int.
NonRationalType |
nonRational |
Definition at line 634 of file Rational.hpp.
|
inlineconstexpr |
Division assignment operation between 2 rationals.
anotherRational |
Definition at line 648 of file Rational.hpp.
|
inlineconstexpr |
Multiplication assignment operation between a rational and another type. Example: Rational * int.
NonRationalType |
nonRational |
Definition at line 660 of file Rational.hpp.
|
inlineconstexpr |
Inverse a rational : a / b into b / a.
Definition at line 674 of file Rational.hpp.
|
constexpr |
Give the square root of a rational.
Definition at line 1057 of file Rational.hpp.
|
constexpr |
Give the cosine of a rational.
Definition at line 1065 of file Rational.hpp.
|
constexpr |
Give the exponential of a rational.
Definition at line 1072 of file Rational.hpp.
|
constexpr |
Give the power of a rational.
Definition at line 1080 of file Rational.hpp.
|
inlineconstexpr |
Give the abs of a rational.
Definition at line 708 of file Rational.hpp.
|
constexprnoexcept |
Simplify the Rational with GCD (called in constructor)
Definition at line 1087 of file Rational.hpp.
|
staticconstexprnoexcept |
Return the minimum between two rationals.
rational1 | |
rational2 |
Definition at line 1103 of file Rational.hpp.
|
staticconstexprnoexcept |
Variadic: Return the minimum between various rationals.
Args |
rational | |
args |
Definition at line 1112 of file Rational.hpp.
|
staticconstexprnoexcept |
Return the maximum between two rationals.
rational1 | |
rational2 |
Definition at line 1124 of file Rational.hpp.
|
staticconstexprnoexcept |
Variadic: Return the maximum between various rationals.
Args |
rational | |
args |
Definition at line 1133 of file Rational.hpp.
|
inlinestaticconstexprnoexcept |
Return zero in Rational Type.
Definition at line 781 of file Rational.hpp.
|
inlinestaticconstexprnoexcept |
Return one in Rational Type.
Definition at line 787 of file Rational.hpp.
|
inlinestaticconstexprnoexcept |
Return Pi in Rational Type.
Definition at line 793 of file Rational.hpp.
|
inlinestaticconstexprnoexcept |
Return an approximation of +infinite in Rational Type.
Definition at line 799 of file Rational.hpp.
|
inlineconstexpr |
Get an approximation of a given Rational. We assume that you don't ask a bigger precision that you don't have.
digitsKept |
Definition at line 1145 of file Rational.hpp.
|
inlineconstexprnoexcept |
Get the integer part of the ratio.
Definition at line 818 of file Rational.hpp.
|
inlineconstexprnoexcept |
Get an approximation floating point number of the ratio.
FloatingType |
Definition at line 829 of file Rational.hpp.
|
inlinenoexcept |
Return ( numerator / denominator ) as a string.
Definition at line 838 of file Rational.hpp.
|
staticconstexpr |
A method who automatically set numerator and denominator to approach the float parameter.
FloatingType |
floatingRatio | |
iter |
|
inlinestaticconstexprnoexcept |
Print the value of a rational.
IntType |
rational |
Definition at line 860 of file Rational.hpp.
|
inlinestaticconstexprnoexcept |
Variadic: Print the values of various rationals.
IntType | |
Args |
rational | |
args |
Definition at line 872 of file Rational.hpp.
|
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.
|
constexprprotected |
Verify if the denominator is null or negative.
denominator | |
checkIfDenominatorIsNull |
Definition at line 1195 of file Rational.hpp.
|
constexprprotected |
Verify if the operands are superior to the limit of IntType.
AnotherIntType |
anotherRational |
Definition at line 1183 of file Rational.hpp.
|
inlinestaticconstexprprotected |
Check for overflow before returning a value.
numerator | |
denominator |
Definition at line 919 of file Rational.hpp.
|
constexpr |
Definition at line 1152 of file Rational.hpp.
|
friend |
Addition operation between a non-rational and a rational. Example: int + Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 176 of file Rational.hpp.
|
friend |
Subtraction operation between a non-rational and a rational. Example: int - Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 213 of file Rational.hpp.
|
friend |
Unary operator, allow to do -Rational.
rational |
Definition at line 225 of file Rational.hpp.
|
friend |
Multiplication operation between a non-rational and a rational. Example: int * Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 259 of file Rational.hpp.
|
friend |
Division operation between a non-rational and a rational. Example: int / Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 296 of file Rational.hpp.
|
friend |
Comparison between a non-rational and a rational. Example: int == Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 339 of file Rational.hpp.
|
friend |
Different comparison between a non-rational and a rational. Example: int != Rational.
NonRationalType |
nonRational | |
rational |
Definition at line 382 of file Rational.hpp.
|
friend |
< Comparison between a non-rational and a rational. Example: int < Rational
NonRationalType |
nonRational | |
rational |
Definition at line 419 of file Rational.hpp.
|
friend |
<= Comparison between a non-rational and a rational. Example: int <= Rational
NonRationalType |
nonRational | |
rational |
Definition at line 458 of file Rational.hpp.
|
friend |
< Comparison between a non-rational and a rational. Example: int > Rational
NonRationalType |
nonRational | |
rational |
Definition at line 497 of file Rational.hpp.
|
friend |
>= Comparison between a non-rational and a rational. Example: int >= Rational
NonRationalType |
nonRational | |
rational |
Definition at line 536 of file Rational.hpp.
|
protected |
Rational's numerator.
Definition at line 883 of file Rational.hpp.
|
protected |
Rational's denominator.
Definition at line 885 of file Rational.hpp.