fractions namespace

Classes

template<typename T>
struct Fraction
Fraction.

Functions

template<typename T>
auto abs(const T& a) -> typename std::enable_if< std::is_unsigned< T >::value, T >::type -> CONSTEXPR14 auto
template<typename _Mn>
auto gcd_recur(const _Mn& __m, const _Mn& __n) -> _Mn -> CONSTEXPR14 auto
template<typename _Mn>
auto gcd(const _Mn& __m, const _Mn& __n) -> _Mn -> CONSTEXPR14 auto
template<typename _Mn>
auto lcm(const _Mn& __m, const _Mn& __n) -> _Mn -> CONSTEXPR14 auto

Function documentation

template<typename T>
CONSTEXPR14 auto fractions::abs(const T& a) -> typename std::enable_if< std::is_unsigned< T >::value, T >::type

Template parameters
T The type of the input parameter.
Parameters
in The input value.
Returns The absolute value of the input.

Returns the absolute value of the input.

For unsigned types, simply returns the input value.

Computes the absolute value of the given signed integer value. Returns the input if it is positive, otherwise returns the negation of the input.

template<typename _Mn>
CONSTEXPR14 auto fractions::gcd_recur(const _Mn& __m, const _Mn& __n) -> _Mn

Template parameters
_Mn The integer type.
Parameters
__m The first integer.
__n The second integer.
Returns The GCD of __m and __n.

Computes the greatest common divider (GCD) of two integers recursively using Euclid's algorithm.

Example:

gcd_recur(12, 8) = 4
gcd_recur(12, 4) = 4
gcd_recur(4, 4) = 4

template<typename _Mn>
CONSTEXPR14 auto fractions::gcd(const _Mn& __m, const _Mn& __n) -> _Mn

Template parameters
_Mn The integer type.
Parameters
__m The first integer.
__n The second integer.
Returns The GCD of __m and __n.

Computes the greatest common divider (GCD) of two integers recursively using Euclid's algorithm.

Example:

gcd(0, 8) = 8
gcd(12, 4) = 4
gcd(4, 4) = 4

template<typename _Mn>
CONSTEXPR14 auto fractions::lcm(const _Mn& __m, const _Mn& __n) -> _Mn

Template parameters
_Mn The integer type.
Parameters
__m The first integer.
__n The second integer.
Returns The least common multiple of __m and __n.

Computes the least common multiple of two integers.

Uses the formula lcm(a, b) = (abs(a) / gcd(a, b)) * abs(b).