fractions namespace
Classes
-
template<typename T>struct ExtFraction
- ExtFraction.
- class Fraction
- Fraction.
Functions
-
template<typename T>auto abs(const T& val_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
-
template<typename T>auto operator==(T lhs, const Fraction<T>& rhs) -> bool
- Equality comparison between integer and Fraction.
-
template<typename T>auto operator<(T lhs, const Fraction<T>& rhs) -> bool
- Less-than comparison between integer and Fraction.
-
template<typename T>auto operator>(T lhs, const Fraction<T>& rhs) -> bool
- Greater-than comparison between integer and Fraction.
-
template<typename T>auto operator<=(T lhs, const Fraction<T>& rhs) -> bool
- Less-than-or-equal comparison between integer and Fraction.
-
template<typename T>auto operator>=(T lhs, const Fraction<T>& rhs) -> bool
- Greater-than-or-equal comparison between integer and Fraction.
-
template<typename T>auto operator+(T lhs, const Fraction<T>& rhs) -> Fraction<T>
- Addition operator for integer on left side.
-
template<typename T>auto operator-(T lhs, const Fraction<T>& rhs) -> Fraction<T>
- Subtraction operator for integer on left side.
-
template<typename T>auto operator*(T lhs, const Fraction<T>& rhs) -> Fraction<T>
- Multiplication operator for integer on left side.
-
template<typename T>auto operator/(T lhs, const Fraction<T>& rhs) -> Fraction<T>
- Division operator for integer on left side.
Function documentation
#include <fractions/extfractions.hpp>
template<typename T>
CONSTEXPR14 auto fractions:: abs(const T& val_a) -> typename std::enable_if< std::is_unsigned< T >::value, T >::type
| Template parameters | |
|---|---|
| T | The type of the input parameter. |
| Parameters | |
| val_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.
+---+ abs() +---+ | 5 | ------> | 5 | +---+ +---+ +----+ abs() +---+ | -5 | ------> | 5 | +----+ +---+ +---+ abs() +---+ | 0 | ------> | 0 | +---+ +---+
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/extfractions.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
gcd(48, 18)
|
v
gcd(18, 12)
|
v
gcd(12, 6)
|
v
gcd(6, 0) = 6
#include <fractions/extfractions.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/extfractions.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).
lcm(4, 6) = 12 4 = 2^2 6 = 2^1 * 3^1 lcm = 2^2 * 3^1 = 12 +-----+ +-----+ +--------+ | 4 | lcm | 6 | = | 12 | +-----+ +-----+ +--------+
#include <fractions/pyfractions.hpp>
template<typename T>
bool fractions:: operator==(T lhs,
const Fraction<T>& rhs)
Equality comparison between integer and Fraction.
| Parameters | |
|---|---|
| lhs | Integer to compare |
| rhs | Fraction to compare |
| Returns | true if rhs equals lhs (i.e., rhs.numerator() == lhs && rhs.denominator() == 1) |
Comparison operators for integer on left side
#include <fractions/pyfractions.hpp>
template<typename T>
bool fractions:: operator<(T lhs,
const Fraction<T>& rhs)
Less-than comparison between integer and Fraction.
| Parameters | |
|---|---|
| lhs | Integer to compare |
| rhs | Fraction to compare |
| Returns | true if lhs is less than rhs |
#include <fractions/pyfractions.hpp>
template<typename T>
bool fractions:: operator>(T lhs,
const Fraction<T>& rhs)
Greater-than comparison between integer and Fraction.
| Parameters | |
|---|---|
| lhs | Integer to compare |
| rhs | Fraction to compare |
| Returns | true if lhs is greater than rhs |
#include <fractions/pyfractions.hpp>
template<typename T>
bool fractions:: operator<=(T lhs,
const Fraction<T>& rhs)
Less-than-or-equal comparison between integer and Fraction.
| Parameters | |
|---|---|
| lhs | Integer to compare |
| rhs | Fraction to compare |
| Returns | true if lhs is less than or equal to rhs |
#include <fractions/pyfractions.hpp>
template<typename T>
bool fractions:: operator>=(T lhs,
const Fraction<T>& rhs)
Greater-than-or-equal comparison between integer and Fraction.
| Parameters | |
|---|---|
| lhs | Integer to compare |
| rhs | Fraction to compare |
| Returns | true if lhs is greater than or equal to rhs |
#include <fractions/pyfractions.hpp>
template<typename T>
Fraction<T> fractions:: operator+(T lhs,
const Fraction<T>& rhs)
Addition operator for integer on left side.
| Parameters | |
|---|---|
| lhs | Integer to add |
| rhs | Fraction to add |
| Returns | Result of lhs + rhs as new Fraction |
Arithmetic operators for integer on left side