#include <fractions/extfractions.hpp>
template<typename T>
ExtFraction struct
| Template parameters | |
|---|---|
| T | |
Example:
ExtFraction<int> f(1, 2); f.numer() = 1; f.denom() = 2;
+-------+ | a | = ExtFraction<T> | --- | | b | +-------+ a = numerator b = denominator
Public functions
- auto ExtFraction(T numer, T denom) -> CONSTEXPR14
- denominator
- auto normalize() -> T -> CONSTEXPR14 auto
- auto keep_denom_positive() -> CONSTEXPR14 void
- auto reduce() -> T -> CONSTEXPR14 auto
- auto ExtFraction(T&& numer) -> CONSTEXPR14 explicit
- auto ExtFraction(const T& numer) -> CONSTEXPR14 explicit
- auto ExtFraction() -> CONSTEXPR14
- auto numer() const noexcept -> const T & -> CONSTEXPR14 auto
- auto denom() const noexcept -> const T & -> CONSTEXPR14 auto
- auto cross(const ExtFraction& rhs) const -> T -> CONSTEXPR14 auto
- auto reciprocal() -> CONSTEXPR14 void
- Inverts the numerator and denominator of the fraction to calculate its reciprocal.
- auto operator*=(ExtFraction rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator*=(T rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator/=(ExtFraction rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator/=(T rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator-() const -> ExtFraction -> CONSTEXPR14 auto
- auto operator+(const ExtFraction& other) const -> ExtFraction -> CONSTEXPR14 auto
- auto operator-(const ExtFraction& other) const -> ExtFraction -> CONSTEXPR14 auto
- auto operator-(const T& rhs) const -> ExtFraction -> CONSTEXPR14 auto
- auto operator+=(const ExtFraction& rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator-=(const ExtFraction& rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator+=(const T& rhs) -> ExtFraction & -> CONSTEXPR14 auto
- auto operator++() -> ExtFraction & -> CONSTEXPR14 auto
- auto operator--() -> ExtFraction & -> CONSTEXPR14 auto
- auto operator++(int) -> ExtFraction -> CONSTEXPR14 auto
- auto operator--(int) -> ExtFraction -> CONSTEXPR14 auto
- auto operator-=(const T& rhs) -> ExtFraction & -> auto
Public variables
Comparison operators
==, !=, <, >, <=, >= etc.
- auto operator!=(const ExtFraction& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator>(const ExtFraction& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator>=(const ExtFraction& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator<=(const ExtFraction& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator>(const T& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator<=(const T& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator>=(const T& rhs) const -> bool -> CONSTEXPR14 auto
- auto operator==(const ExtFraction& lhs, const T& rhs) -> bool -> CONSTEXPR14 auto
- auto operator<(const ExtFraction& lhs, const T& rhs) -> bool -> CONSTEXPR14 auto
- auto operator<(const T& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator==(const T& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator==(const ExtFraction& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator<(const ExtFraction& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator>(const T& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator<=(const T& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
- auto operator>=(const T& lhs, const ExtFraction& rhs) -> bool -> CONSTEXPR14 auto
Friends
- auto operator*(ExtFraction lhs, const ExtFraction& rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator*(ExtFraction lhs, const T& rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator*(const T& lhs, ExtFraction rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator/(ExtFraction lhs, const ExtFraction& rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator/(ExtFraction lhs, const T& rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator/(const T& lhs, ExtFraction rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator+(ExtFraction lhs, const T& rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator+(const T& lhs, ExtFraction rhs) -> ExtFraction -> CONSTEXPR14 auto
- auto operator-(const T& val, const ExtFraction& frac) -> ExtFraction -> CONSTEXPR14 auto
- auto operator+(int&& val, const ExtFraction& frac) -> ExtFraction -> CONSTEXPR14 auto
- auto operator-(int&& val, const ExtFraction& frac) -> ExtFraction -> CONSTEXPR14 auto
- auto operator*(int&& val, const ExtFraction& frac) -> ExtFraction -> CONSTEXPR14 auto
-
template<typename _Stream>auto operator<<(_Stream& out_stream, const ExtFraction& frac) -> _Stream & -> auto
Function documentation
template<typename T>
CONSTEXPR14 fractions:: ExtFraction<T>:: ExtFraction(T numer,
T denom)
denominator
| Parameters | |
|---|---|
| numer in | The numerator |
| denom in | The denominator |
Constructs a new ExtFraction (Extended Fraction) object from the given numerator and denominator.
Normalizes the fraction after construction.
Example: ExtFraction<int> f(1, 2); // f = 1/2
numer = 6, denom = 8
|
v
+-------+
| 6 | normalize() +-------+
| --- | ----------------> | 3 |
| 8 | | --- |
+-------+ | 4 |
+-------+
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: normalize() -> T
Normalizes the fraction to a canonical form where the denominator is always non-negative and co-prime with the numerator.
+-------+ normalize() +-------+ | 6 | --------------> | 3 | | --- | | --- | | 8 | | 4 | +-------+ +-------+ +-------+ normalize() +-------+ | -3 | --------------> | 3 | | --- | | --- | | -4 | | 4 | +-------+ +-------+
template<typename T>
CONSTEXPR14 void fractions:: ExtFraction<T>:: keep_denom_positive()
Normalizes the fraction by making the denominator positive. If the denominator is negative, both numerator and denominator are negated. This ensures the denominator is always positive.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: reduce() -> T
Normalizes the fraction to a canonical form by making the numerator and denominator coprime. The gcd of the numerator and denominator is computed and used to divide out any common factors.
Example:
ExtFraction<int> f(2, 6); // f = 1/3 f.reduce();
template<typename T>
CONSTEXPR14 fractions:: ExtFraction<T>:: ExtFraction(T&& numer) explicit
| Parameters | |
|---|---|
| numer in | The numerator. |
Constructs a new ExtFraction object from the given numerator.
The denominator is initialized to 1.
Example:
ExtFraction<int> f(2); // f = 2/1 assert(f.numer() == 2 && f.denom() == 1);
template<typename T>
CONSTEXPR14 fractions:: ExtFraction<T>:: ExtFraction(const T& numer) explicit
| Parameters | |
|---|---|
| numer in | The numerator. |
Constructs a new ExtFraction object from the given numerator.
The denominator is initialized to 1.
Example:
ExtFraction<int> f(2); // f = 2/1 assert(f == ExtFraction<int>(2, 1));
template<typename T>
CONSTEXPR14 fractions:: ExtFraction<T>:: ExtFraction()
Constructs a new ExtFraction object with numerator initialized to 0 and denominator initialized to 1.
Example:
ExtFraction<int> f; // f = 0/1 assert(f.numer() == 0);
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: numer() const noexcept -> const T &
| Returns | A const reference to the numerator. |
|---|
Gets the numerator of the fraction.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: denom() const noexcept -> const T &
| Returns | A const reference to the denominator. |
|---|
Gets the denominator of the fraction.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: cross(const ExtFraction& rhs) const -> T
| Parameters | |
|---|---|
| rhs in | The right-hand fraction to compute the cross product with. |
| Returns | The computed cross product. |
Computes the cross product of this fraction and another fraction.
The cross product is defined as: cross(a/b, c/d) = a*d - b*c
This can be used to compute the determinant of a 2x2 matrix with the two fractions as the entries on the diagonal.
Example:
cross(ExtFraction(1,2), ExtFraction(3,4)) = -1 cross(ExtFraction(1,2), ExtFraction(1,2)) = 0 cross(ExtFraction(1,2), ExtFraction(-1,2)) = 0
a c --- x --- = a*d - b*c b d +-------+ +-------+ | a | | c | | --- | x | --- | = a*d - b*c | b | | d | +-------+ +-------+ cross(1/2, 3/4) = 1*4 - 2*3 = -2
template<typename T>
CONSTEXPR14 void fractions:: ExtFraction<T>:: reciprocal()
Inverts the numerator and denominator of the fraction to calculate its reciprocal.
+-------+ reciprocal() +-------+ | a | ----------> | b | | --- | | --- | | b | | a | +-------+ +-------+ +-------+ reciprocal() +-------+ | 2 | ----------> | 3 | | --- | | --- | | 3 | | 2 | +-------+ +-------+
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator*=(ExtFraction rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The ExtFraction to multiply. |
| Returns | A reference to this ExtFraction after multiplication. |
Multiplies this ExtFraction by the given ExtFraction rhs and assigns the result to this ExtFraction.
Normalizes this ExtFraction and rhs before multiplying. Updates the numerator and denominator of this ExtFraction with the result.
a c a*c
--- * --- = -----
b d b*d
+-------+ +-------+ +---------+
| a | | c | | a*c |
| --- | * | --- | = | ----- |
| b | | d | | b*d |
+-------+ +-------+ +---------+
+-------+ +-------+ +-------+
| 1 | | 2 | | 2 |
| --- | * | --- | = | --- |
| 2 | | 3 | | 6 |
+-------+ +-------+ +-------+
normalize
+-------+ ----------> +-------+
| 2 | | 1 |
| --- | | --- |
| 6 | | 3 |
+-------+ +-------+
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator*=(T rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The integer to multiply. |
| Returns | A reference to this ExtFraction after multiplication. |
Multiplies this ExtFraction by the given integer rhs and assigns the result to this ExtFraction.
Normalizes this ExtFraction before multiplying. Updates the numerator of this ExtFraction with the result and retains the existing denominator.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator/=(ExtFraction rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The ExtFraction to divide by. |
| Returns | A reference to this ExtFraction after division. |
Divides this ExtFraction by the given ExtFraction rhs and assigns the result to this ExtFraction.
Swaps the denominator of this ExtFraction with the numerator of rhs. Normalizes this ExtFraction and rhs before dividing. Updates the numerator and denominator of this ExtFraction with the result.
a c a d a*d --- / --- = --- * --- = ----- b d b c b*c +-------+ +-------+ +-------+ +---------+ | a | | c | | a | | a*d | | --- | / | --- | = | --- | * | ----- | | b | | d | | b | | b*c | +-------+ +-------+ +-------+ +---------+ +-------+ +-------+ +-------+ | 1 | | 2 | | 3 | | --- | / | --- | = | --- | | 2 | | 3 | | 4 | +-------+ +-------+ +-------+
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator/=(T rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The integer to divide this ExtFraction by. |
| Returns | A reference to this ExtFraction after dividing by rhs. |
Divides this ExtFraction by the integer rhs and assigns the result to this ExtFraction.
Divides the numerator of this ExtFraction by rhs and updates it with the result.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator-() const -> ExtFraction
Negates this ExtFraction by negating its numerator.
Returns a new ExtFraction with the negated numerator.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator+(const ExtFraction& other) const -> ExtFraction
Adds this ExtFraction to the ExtFraction rhs.
Finds the lowest common denominator and converts both Fractions to it. Then adds the numerators and returns a new ExtFraction with the result. Handles zero denominators by returning a ExtFraction with a zero denominator.
a c a*d + b*c --- + --- = --------- b d b*d +-------+ +-------+ +-----------+ | a | | c | | a*d+b*c | | --- | + | --- | = | ------ | | b | | d | | b*d | +-------+ +-------+ +-----------+ +-------+ +-------+ +-------+ | 1 | | 1 | | 5 | | --- | + | --- | = | --- | | 2 | | 3 | | 6 | +-------+ +-------+ +-------+
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator-(const ExtFraction& other) const -> ExtFraction
| Parameters | |
|---|---|
| other in | The ExtFraction to subtract from this one. |
| Returns | A new ExtFraction containing the result. |
Subtracts another ExtFraction from this ExtFraction.
Negates the passed in ExtFraction, then adds it to this ExtFraction.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator-(const T& rhs) const -> ExtFraction
| Parameters | |
|---|---|
| rhs | The integer to subtract. |
| Returns | A new ExtFraction containing the difference. |
Subtracts an integer from this ExtFraction.
Converts the integer rhs to a ExtFraction with denominator 1 and subtracts it from this ExtFraction.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator+=(const ExtFraction& rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs in | The ExtFraction to add. |
| Returns | A reference to this ExtFraction after adding. |
Adds another ExtFraction to this ExtFraction.
If the denominators are equal, simply add the numerators. Otherwise, find the greatest common divisor of both denominators, multiply the numerators by the denominator over the gcd, add the new numerators, multiply by the product of the original denominators, and reduce to lowest terms.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator-=(const ExtFraction& rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The ExtFraction to subtract. |
| Returns | A reference to this ExtFraction after subtracting. |
Subtracts another ExtFraction from this ExtFraction.
If the denominators are equal, simply subtract the numerators. Otherwise, find the greatest common divisor of both denominators, multiply the numerators by the denominator over the gcd, subtract the new numerators, multiply by the product of the original denominators, and reduce to lowest terms.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator+=(const T& rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs in | The T (integer) to add. |
| Returns | A reference to this ExtFraction after adding. |
Adds a T (integer) to this ExtFraction.
If the denominator is 1, simply add to the numerator. Otherwise, multiply the T by the denominator and add to the numerator. Then, reduce to lowest terms.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator++() -> ExtFraction &
| Returns | A reference to this ExtFraction after incrementing. |
|---|
Increments this ExtFraction by 1.
Adds 1 to this ExtFraction
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator--() -> ExtFraction &
| Returns | A reference to this ExtFraction after decrementing. |
|---|
Decrements this ExtFraction by 1.
Subtracts 1 from this ExtFraction by calling operator-=() with a T (integer) value of 1.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator++(int) -> ExtFraction
Post-increment operator.
Makes a copy of this ExtFraction, increments the copy, and returns the copy.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator--(int) -> ExtFraction
Post-decrement operator.
Makes a copy of this ExtFraction, decrements the copy, and returns the copy.
template<typename T>
auto fractions:: ExtFraction<T>:: operator-=(const T& rhs) -> ExtFraction &
| Parameters | |
|---|---|
| rhs | The integer to subtract. |
| Returns | A reference to this fraction after subtracting. |
Subtracts an integer from this fraction.
If the denominator is 1, simply subtract from the numerator. Otherwise, multiply the integer by the denominator and subtract from the numerator. Then, reduce to lowest terms.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator!=(const ExtFraction& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare against. |
| Returns | True if the fractions are not equal, false if they are equal. |
Compares this fraction for inequality against another fraction.
Returns true if this fraction and the given fraction represent different rational values, false if they are equal. Uses the equality operator to compare the two fractions.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>(const ExtFraction& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is greater than rhs, false otherwise. |
Compares this fraction to another fraction for greater than.
Returns true if this fraction is greater than the other fraction, false otherwise. Greater than is determined by converting to a common denominator and comparing the resulting numerators.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>=(const ExtFraction& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is greater than or equal to the other fraction, false otherwise. |
Compares this fraction to another fraction for greater than or equal to.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<=(const ExtFraction& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is less than or equal to the other fraction, false otherwise. |
Compares this fraction to another fraction for less than or equal to.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>(const T& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is greater than the other T integer, false otherwise. |
Compares this fraction to another T integer for greater than.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<=(const T& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is less than or equal to the other T integer, false otherwise. |
Compares this fraction to another T integer for less than or equal to.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>=(const T& rhs) const -> bool
| Parameters | |
|---|---|
| rhs | The right hand side fraction to compare. |
| Returns | True if this fraction is greater than or equal to the other T integer, false otherwise. |
Compares this fraction to another T integer for greater than or equal to.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator==(const ExtFraction& lhs,
const T& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side fraction to compare. |
| rhs | The right hand side integer to compare. |
| Returns | True if lhs == rhs, false otherwise. |
Compares this fraction to an integer value for equality.
Returns true if the fraction is equal to the integer, false otherwise. The fraction is considered equal if its normalized value matches the integer when the denominator is 1.
Example: ExtFraction(1, 1) == 1 -> true ExtFraction(1, 2) == 2 -> false ExtFraction(1, 2) == 3 -> false
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<(const ExtFraction& lhs,
const T& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side fraction to compare. |
| rhs | The right hand side integer to compare. |
| Returns | True if lhs < rhs, false otherwise. |
Compares this fraction to an integer value for less than.
Returns true if this fraction is less than the integer, false otherwise. The fraction is considered less if its normalized value is less than the integer when the denominator is 1.
Example: ExtFraction(1, 1) < 1 -> false ExtFraction(1, 2) < 2 -> true ExtFraction(1, 2) < 3 -> true
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<(const T& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side integer to compare. |
| rhs | The right hand side fraction to compare. |
| Returns | True if lhs < rhs, false otherwise. |
Compares an integer value to this fraction for less than.
Returns true if the integer is less than this fraction, false otherwise. The fraction is considered greater if its normalized value is greater than the integer when the denominator is 1.
Example: 1 < ExtFraction(1, 1) -> false 2 < ExtFraction(1, 2) -> false 3 < ExtFraction(7, 2) -> true
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator==(const T& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side integer to compare. |
| rhs | The right hand side fraction to compare. |
| Returns | True if lhs == rhs, false otherwise. |
Compares an integer value to this fraction for equality.
Returns true if the integer is equal to this fraction, false otherwise. Equality is checked by comparing the integer to the normalized value of the fraction.
Example: 1 == ExtFraction(1, 1) -> true 2 == ExtFraction(1, 2) -> false 3 == ExtFraction(7, 2) -> false
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator==(const ExtFraction& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side fraction to compare. |
| rhs | The right hand side fraction to compare. |
| Returns | True if lhs == rhs, false otherwise. |
Compares this fraction to another fraction for equality.
Returns true if the two fractions represent the same rational value, false otherwise. Equality is checked by normalizing both fractions to a common denominator and comparing the numerators.
Example: ExtFraction(1, 1) == ExtFraction(1, 1) -> true ExtFraction(1, 2) == ExtFraction(2, 4) -> true ExtFraction(1, 2) == ExtFraction(3, 4) -> false
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<(const ExtFraction& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The left hand side fraction to compare. |
| rhs | The right hand side fraction to compare. |
| Returns | True if lhs < rhs, false otherwise. |
Compares this fraction to another fraction for less than.
Returns true if this fraction is less than the other fraction, false otherwise. Less than is determined by converting both fractions to a common denominator and comparing the resulting numerators.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>(const T& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The T integer on the left hand side. |
| rhs | The ExtFraction on the right hand side. |
| Returns | True if lhs is greater than rhs, false otherwise. |
Compares a T integer to a ExtFraction for greater than.
This is a friend function that allows comparing a T integer on the left hand side to a ExtFraction on the right hand side.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator<=(const T& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The T integer on the left hand side. |
| rhs | The ExtFraction on the right hand side. |
| Returns | True if lhs is less than or equal to rhs, false otherwise. |
Compares a T integer to a ExtFraction for less than or equal to.
This is a friend function that allows comparing a T integer on the left hand side to a ExtFraction on the right hand side.
template<typename T>
CONSTEXPR14 auto fractions:: ExtFraction<T>:: operator>=(const T& lhs,
const ExtFraction& rhs) -> bool
| Parameters | |
|---|---|
| lhs | The T integer on the left hand side. |
| rhs | The ExtFraction on the right hand side. |
| Returns | True if lhs is greater than or equal to rhs, false otherwise. |
Compares a T integer to a ExtFraction for greater than or equal to.
This is a friend function that allows comparing a T integer on the left hand side to a ExtFraction on the right hand side.
template<typename T>
CONSTEXPR14 auto operator*(ExtFraction lhs,
const ExtFraction& rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs | The left hand ExtFraction to multiply. |
| rhs | The right hand ExtFraction to multiply. |
| Returns | A new ExtFraction containing the result of the multiplication. |
Multiplies the given ExtFraction lhs by the ExtFraction rhs.
Normalizes lhs and rhs before multiplying. Returns a new ExtFraction containing the result of the multiplication.
template<typename T>
CONSTEXPR14 auto operator*(ExtFraction lhs,
const T& rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs | The left hand ExtFraction to multiply. |
| rhs | The right hand integer to multiply. |
| Returns | A new ExtFraction containing the result of the multiplication. |
Multiplies the given ExtFraction lhs by the integer rhs.
Normalizes lhs before multiplying. Returns a new ExtFraction containing the result of the multiplication.
template<typename T>
CONSTEXPR14 auto operator*(const T& lhs,
ExtFraction rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs | The left hand integer to multiply. |
| rhs | The right hand ExtFraction to multiply. |
| Returns | A new ExtFraction containing the result of the multiplication. |
Multiplies the ExtFraction rhs by the integer lhs.
Normalizes rhs before multiplying. Returns a new ExtFraction containing the result of the multiplication.
template<typename T>
CONSTEXPR14 auto operator/(ExtFraction lhs,
const ExtFraction& rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs in | |
| rhs in | |
| Returns | A ExtFraction after division. |
Divides the ExtFraction lhs by the ExtFraction rhs.
Returns a new ExtFraction containing the result.
template<typename T>
CONSTEXPR14 auto operator/(ExtFraction lhs,
const T& rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs in | |
| rhs in | |
| Returns | A ExtFraction after division. |
Divides the ExtFraction lhs by the integer rhs.
template<typename T>
CONSTEXPR14 auto operator/(const T& lhs,
ExtFraction rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs in | |
| rhs in | |
| Returns | A ExtFraction after division. |
Divides the integer lhs by the ExtFraction rhs.
Returns a new ExtFraction containing the result.
template<typename T>
CONSTEXPR14 auto operator+(ExtFraction lhs,
const T& rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs | The ExtFraction to add to. |
| rhs | The integer to add. |
| Returns | A new ExtFraction containing the sum. |
Adds a ExtFraction and an integer.
Converts the integer to a ExtFraction and adds it to the ExtFraction lhs.
template<typename T>
CONSTEXPR14 auto operator+(const T& lhs,
ExtFraction rhs) -> ExtFraction
| Parameters | |
|---|---|
| lhs | The ExtFraction to add to. |
| rhs | The integer to add. |
| Returns | A new ExtFraction containing the sum. |
Adds an integer to a ExtFraction.
Converts the integer rhs to a ExtFraction and adds it to the ExtFraction lhs.
template<typename T>
CONSTEXPR14 auto operator-(const T& val,
const ExtFraction& frac) -> ExtFraction
| Parameters | |
|---|---|
| val | The integer to subtract. |
| frac | The ExtFraction to subtract from. |
| Returns | A new ExtFraction containing the difference. |
Subtracts a T integer from this ExtFraction.
Subtracts the integer val from this ExtFraction frac. Returns the result as a new ExtFraction.
template<typename T>
CONSTEXPR14 auto operator+(int&& val,
const ExtFraction& frac) -> ExtFraction
| Parameters | |
|---|---|
| val | The integer to add. |
| frac | The ExtFraction to add to. |
| Returns | A new ExtFraction containing the sum. |
Adds an integer to a ExtFraction.
This friend function allows adding an integer and a ExtFraction by converting the integer to a ExtFraction and delegating to the ExtFraction += operator.
template<typename T>
CONSTEXPR14 auto operator-(int&& val,
const ExtFraction& frac) -> ExtFraction
| Parameters | |
|---|---|
| val | The integer to subtract. |
| frac | The ExtFraction to subtract from. |
| Returns | A new ExtFraction containing the difference. |
Subtracts an integer from a ExtFraction.
This allows subtracting an integer from a ExtFraction by first converting the integer to a ExtFraction.
template<typename T>
CONSTEXPR14 auto operator*(int&& val,
const ExtFraction& frac) -> ExtFraction
| Parameters | |
|---|---|
| val | The integer value to multiply. |
| frac | The ExtFraction to multiply. |
| Returns | A new ExtFraction containing the product. |
Multiplies an integer by a ExtFraction.
This friend function converts the integer to a ExtFraction and delegates to the ExtFraction *= operator to perform the multiplication.
template<typename T>
template<typename _Stream>
auto operator<<(_Stream& out_stream,
const ExtFraction& frac) -> _Stream &
| Template parameters | |
|---|---|
| _Stream | |
| Parameters | |
| out_stream in | |
| frac in | |
| Returns | _Stream& |
Overloads the stream output operator to print a ExtFraction to a stream.
This allows printing a ExtFraction to an output stream in the format "(numerator/denominator)".