template<Integral Z>
fun::Fraction struct

Fraction.

Template parameters
Z

Constructors, destructors, conversion operators

Fraction(Z num, Z den) constexpr
Construct a new Fraction object.
Fraction(Z&& num) explicit constexpr
Construct a new Fraction object.
Fraction(const Z& num) explicit constexpr
Construct a new Fraction object.
Fraction() constexpr
Construct a new Fraction object.

Public functions

auto normalize() -> Z -> auto constexpr
normalize to a canonical form
void normalize1() constexpr
normalize to a canonical form
auto normalize2() -> Z -> auto constexpr
normalize to a canonical form
auto num() const noexcept -> const Z & -> auto constexpr
auto den() const noexcept -> const Z & -> auto constexpr
auto cross(const Fraction& rhs) const -> Z -> auto constexpr
cross product
void reciprocal() constexpr noexcept(…)
reciprocal
auto operator*=(Fraction rhs) -> Fraction & -> auto constexpr
multiply and assign
auto operator*=(Z rhs) -> Fraction & -> auto constexpr
multiply and assign
auto operator/=(Fraction rhs) -> Fraction & -> auto constexpr
divide and assign
auto operator/=(const Z& rhs) -> Fraction & -> auto constexpr
divide and assign
auto operator-() const -> Fraction -> auto constexpr
Negate.
auto operator+(const Fraction& rhs) const -> Fraction -> auto constexpr
Add.
auto operator-(const Fraction& frac) const -> Fraction -> auto constexpr
Subtract.
auto operator-(const Z& i) const -> Fraction -> auto constexpr
auto operator+=(const Fraction& rhs) -> Fraction & -> auto constexpr
auto operator-=(const Fraction& rhs) -> Fraction & -> auto constexpr
auto operator+=(const Z& i) -> Fraction & -> auto constexpr
auto operator-=(const Z& rhs) -> Fraction & -> auto constexpr

Public variables

Z _num
Z _den

Comparison operators

==, !=, <, >, <=, >= etc.

auto operator!=(const Fraction& rhs) const -> bool -> auto constexpr
auto operator>(const Fraction& rhs) const -> bool -> auto constexpr
Greater than.
auto operator>=(const Fraction& rhs) const -> bool -> auto constexpr
Greater than or euqal to.
auto operator<=(const Fraction& rhs) const -> bool -> auto constexpr
Less than or equal to.
auto operator>(const Z& rhs) const -> bool -> auto constexpr
Greater than.
auto operator<=(const Z& rhs) const -> bool -> auto constexpr
Less than or equal to.
auto operator>=(const Z& rhs) const -> bool -> auto constexpr
Greater than or equal to.
auto operator==(Fraction lhs, Z rhs) -> bool -> friend auto constexpr
Equal to.
auto operator<(Fraction lhs, Z rhs) -> bool -> friend auto constexpr
Less than.
auto operator<(Z lhs, Fraction rhs) -> bool -> friend auto constexpr
Less than.
auto operator==(const Z& lhs, const Fraction& rhs) -> bool -> friend auto constexpr
Equal to.
auto operator==(Fraction lhs, Fraction rhs) -> bool -> friend auto constexpr
Equal to.
auto operator<(Fraction lhs, Fraction rhs) -> bool -> friend auto constexpr
Less than.
auto operator>(const Z& lhs, const Fraction& rhs) -> bool -> friend auto constexpr
Greater than.
auto operator<=(const Z& lhs, const Fraction& rhs) -> bool -> friend auto constexpr
Less than or equal to.
auto operator>=(const Z& lhs, const Fraction& rhs) -> bool -> friend auto constexpr
Greater than or euqal to.

Friends

auto operator*(Fraction lhs, const Fraction& rhs) -> Fraction -> friend auto constexpr
multiply
auto operator*(Fraction lhs, const Z& rhs) -> Fraction -> friend auto constexpr
multiply
auto operator*(const Z& lhs, Fraction rhs) -> Fraction -> friend auto constexpr
multiply
auto operator/(Fraction lhs, const Fraction& rhs) -> Fraction -> friend auto constexpr
divide
auto operator/(Fraction lhs, const Z& rhs) -> Fraction -> friend auto constexpr
divide
auto operator/(const Z& lhs, Fraction rhs) -> Fraction -> friend auto constexpr
divide
auto operator+(Fraction frac, const Z& i) -> Fraction -> friend auto constexpr
Add.
auto operator+(const Z& i, Fraction frac) -> Fraction -> friend auto constexpr
Add.
auto operator-(const Z& c, const Fraction& frac) -> Fraction -> friend auto constexpr
auto operator+(int&& c, const Fraction& frac) -> Fraction -> friend auto constexpr
auto operator-(int&& c, const Fraction& frac) -> Fraction -> friend auto constexpr
auto operator*(int&& c, const Fraction& frac) -> Fraction -> friend auto constexpr
template<typename _Stream>
auto operator<<(_Stream& os, const Fraction& frac) -> _Stream & -> auto

Function documentation

template<Integral Z>
fun::Fraction<Z>::Fraction(Z num, Z den) constexpr

Construct a new Fraction object.

Parameters
num in
den in

template<Integral Z>
fun::Fraction<Z>::Fraction(Z&& num) explicit constexpr

Construct a new Fraction object.

Parameters
num in

template<Integral Z>
fun::Fraction<Z>::Fraction(const Z& num) explicit constexpr

Construct a new Fraction object.

Parameters
num in

template<Integral Z>
auto fun::Fraction<Z>::normalize() -> Z constexpr

normalize to a canonical form

denominator is always non-negative and co-prime with numerator

template<Integral Z>
void fun::Fraction<Z>::normalize1() constexpr

normalize to a canonical form

denominator is always non-negative

template<Integral Z>
auto fun::Fraction<Z>::normalize2() -> Z constexpr

normalize to a canonical form

denominator is always co-prime with numerator

template<Integral Z>
auto fun::Fraction<Z>::num() const noexcept -> const Z & constexpr

Returns const Z&

template<Integral Z>
auto fun::Fraction<Z>::den() const noexcept -> const Z & constexpr

Returns const Z&

template<Integral Z>
auto fun::Fraction<Z>::cross(const Fraction& rhs) const -> Z constexpr

cross product

Parameters
rhs
Returns Z

template<Integral Z>
auto fun::Fraction<Z>::operator*=(Fraction rhs) -> Fraction & constexpr

multiply and assign

Parameters
rhs
Returns Fraction&

template<Integral Z>
auto fun::Fraction<Z>::operator*=(Z rhs) -> Fraction & constexpr

multiply and assign

Parameters
rhs
Returns Fraction&

template<Integral Z>
auto fun::Fraction<Z>::operator/=(Fraction rhs) -> Fraction & constexpr

divide and assign

Parameters
rhs
Returns Fraction&

template<Integral Z>
auto fun::Fraction<Z>::operator/=(const Z& rhs) -> Fraction & constexpr

divide and assign

Parameters
rhs
Returns Fraction&

template<Integral Z>
auto fun::Fraction<Z>::operator-() const -> Fraction constexpr

Negate.

Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator+(const Fraction& rhs) const -> Fraction constexpr

Add.

Parameters
rhs
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator-(const Fraction& frac) const -> Fraction constexpr

Subtract.

Parameters
frac in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator-(const Z& i) const -> Fraction constexpr

Parameters
in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator+=(const Fraction& rhs) -> Fraction & constexpr

Parameters
rhs in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator-=(const Fraction& rhs) -> Fraction & constexpr

Parameters
rhs in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator+=(const Z& i) -> Fraction & constexpr

Parameters
in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator-=(const Z& rhs) -> Fraction & constexpr

Parameters
rhs in
Returns Fraction

template<Integral Z>
auto fun::Fraction<Z>::operator!=(const Fraction& rhs) const -> bool constexpr

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator>(const Fraction& rhs) const -> bool constexpr

Greater than.

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator>=(const Fraction& rhs) const -> bool constexpr

Greater than or euqal to.

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator<=(const Fraction& rhs) const -> bool constexpr

Less than or equal to.

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator>(const Z& rhs) const -> bool constexpr

Greater than.

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator<=(const Z& rhs) const -> bool constexpr

Less than or equal to.

Parameters
rhs in
Returns true

template<Integral Z>
auto fun::Fraction<Z>::operator>=(const Z& rhs) const -> bool constexpr

Greater than or equal to.

Parameters
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator==(Fraction lhs, Z rhs) -> bool constexpr

Equal to.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator<(Fraction lhs, Z rhs) -> bool constexpr

Less than.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator<(Z lhs, Fraction rhs) -> bool constexpr

Less than.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator==(const Z& lhs, const Fraction& rhs) -> bool constexpr

Equal to.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator==(Fraction lhs, Fraction rhs) -> bool constexpr

Equal to.

Parameters
lhs
rhs
Returns true

Equal to

template<Integral Z>
friend auto fun::Fraction<Z>::operator<(Fraction lhs, Fraction rhs) -> bool constexpr

Less than.

Parameters
lhs
rhs
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator>(const Z& lhs, const Fraction& rhs) -> bool constexpr

Greater than.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator<=(const Z& lhs, const Fraction& rhs) -> bool constexpr

Less than or equal to.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto fun::Fraction<Z>::operator>=(const Z& lhs, const Fraction& rhs) -> bool constexpr

Greater than or euqal to.

Parameters
lhs in
rhs in
Returns true

template<Integral Z>
friend auto operator*(Fraction lhs, const Fraction& rhs) -> Fraction constexpr

multiply

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator*(Fraction lhs, const Z& rhs) -> Fraction constexpr

multiply

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator*(const Z& lhs, Fraction rhs) -> Fraction constexpr

multiply

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator/(Fraction lhs, const Fraction& rhs) -> Fraction constexpr

divide

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator/(Fraction lhs, const Z& rhs) -> Fraction constexpr

divide

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator/(const Z& lhs, Fraction rhs) -> Fraction constexpr

divide

Parameters
lhs
rhs
Returns Fraction

template<Integral Z>
friend auto operator+(Fraction frac, const Z& i) -> Fraction constexpr

Add.

Parameters
frac in
in
Returns Fraction

template<Integral Z>
friend auto operator+(const Z& i, Fraction frac) -> Fraction constexpr

Add.

Parameters
in
frac in
Returns Fraction

template<Integral Z>
friend auto operator-(const Z& c, const Fraction& frac) -> Fraction constexpr

Parameters
in
frac in
Returns Fraction

template<Integral Z>
friend auto operator+(int&& c, const Fraction& frac) -> Fraction constexpr

Parameters
in
frac in
Returns Fraction

template<Integral Z>
friend auto operator-(int&& c, const Fraction& frac) -> Fraction constexpr

Parameters
in
frac in
Returns Fraction

template<Integral Z>
friend auto operator*(int&& c, const Fraction& frac) -> Fraction constexpr

Parameters
in
frac in
Returns Fraction<Z>

template<Integral Z> template<typename _Stream>
auto operator<<(_Stream& os, const Fraction& frac) -> _Stream &

Template parameters
_Stream
Parameters
os in
frac in
Returns _Stream&