fractions namespace
Classes
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
#include <fractions/fractions.hpp>
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 | |
| a 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.
#include <fractions/fractions.hpp>
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
#include <fractions/fractions.hpp>
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
#include <fractions/fractions.hpp>
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).