Py2Cpp 1.6.3; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Friends | List of all members
fun::Fraction< Z > Struct Template Reference

Fraction. More...

#include <fractions.hpp>

Public Member Functions

CONSTEXPR14 Fraction (Z num, Z den)
 Construct a new Fraction object.
 
CONSTEXPR14 auto normalize () -> Z
 normalize to a canonical form
 
CONSTEXPR14 void normalize1 ()
 normalize to a canonical form
 
CONSTEXPR14 auto normalize2 () -> Z
 normalize to a canonical form
 
CONSTEXPR14 Fraction (Z &&num)
 Construct a new Fraction object.
 
CONSTEXPR14 Fraction (const Z &num)
 Construct a new Fraction object.
 
CONSTEXPR14 Fraction ()
 Construct a new Fraction object (default constructor)
 
CONSTEXPR14 auto num () const noexcept -> const Z &
 Get the numerator.
 
CONSTEXPR14 auto den () const noexcept -> const Z &
 Get the denominator.
 
CONSTEXPR14 auto cross (const Fraction &rhs) const -> Z
 cross product
 
CONSTEXPR14 void reciprocal ()
 reciprocal
 
CONSTEXPR14 auto operator*= (Fraction rhs) -> Fraction &
 multiply and assign
 
CONSTEXPR14 auto operator*= (Z rhs) -> Fraction &
 multiply and assign
 
CONSTEXPR14 auto operator/= (Fraction rhs) -> Fraction &
 divide and assign
 
CONSTEXPR14 auto operator/= (Z rhs) -> Fraction &
 divide and assign
 
CONSTEXPR14 auto operator- () const -> Fraction
 Negate.
 
CONSTEXPR14 auto operator+ (const Fraction &rhs) const -> Fraction
 Add.
 
CONSTEXPR14 auto operator- (const Fraction &frac) const -> Fraction
 Subtract.
 
CONSTEXPR14 auto operator- (const Z &i) const -> Fraction
 Subtract an integer from the fraction.
 
CONSTEXPR14 auto operator+= (const Fraction &rhs) -> Fraction &
 Add and assign a fraction.
 
CONSTEXPR14 auto operator-= (const Fraction &rhs) -> Fraction &
 Subtract and assign a fraction.
 
CONSTEXPR14 auto operator+= (const Z &i) -> Fraction &
 Add and assign an integer.
 
CONSTEXPR14 auto operator-= (const Z &rhs) -> Fraction &
 Subtract and assign an integer.
 

Public Attributes

_num
 
_den
 

Friends

CONSTEXPR14 auto operator* (Fraction lhs, const Fraction &rhs) -> Fraction
 multiply
 
CONSTEXPR14 auto operator* (Fraction lhs, const Z &rhs) -> Fraction
 multiply
 
CONSTEXPR14 auto operator* (const Z &lhs, Fraction rhs) -> Fraction
 multiply
 
CONSTEXPR14 auto operator/ (Fraction lhs, const Fraction &rhs) -> Fraction
 divide
 
CONSTEXPR14 auto operator/ (Fraction lhs, const Z &rhs) -> Fraction
 divide
 
CONSTEXPR14 auto operator/ (const Z &lhs, Fraction rhs) -> Fraction
 divide
 
CONSTEXPR14 auto operator+ (Fraction frac, const Z &i) -> Fraction
 Add.
 
CONSTEXPR14 auto operator+ (const Z &i, Fraction frac) -> Fraction
 Add.
 
CONSTEXPR14 auto operator- (const Z &c, const Fraction &frac) -> Fraction
 Subtract a fraction from an integer.
 
CONSTEXPR14 auto operator+ (int &&c, const Fraction &frac) -> Fraction
 Add a fraction to an integer rvalue.
 
CONSTEXPR14 auto operator- (int &&c, const Fraction &frac) -> Fraction
 Subtract a fraction from an integer rvalue.
 
CONSTEXPR14 auto operator* (int &&c, const Fraction &frac) -> Fraction
 Multiply a fraction by an integer rvalue.
 
template<typename Stream >
auto operator<< (Stream &os, const Fraction &frac) -> Stream &
 Stream output operator for Fraction.
 

Comparison operators

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

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

Detailed Description

template<typename Z>
struct fun::Fraction< Z >

Fraction.

Template Parameters
ZThe integer type for numerator and denominator

Constructor & Destructor Documentation

◆ Fraction() [1/4]

template<typename Z >
CONSTEXPR14 fun::Fraction< Z >::Fraction ( num,
den 
)
inline

Construct a new Fraction object.

Parameters
[in]num
[in]den

◆ Fraction() [2/4]

template<typename Z >
CONSTEXPR14 fun::Fraction< Z >::Fraction ( Z &&  num)
inlineexplicit

Construct a new Fraction object.

Parameters
[in]num

◆ Fraction() [3/4]

template<typename Z >
CONSTEXPR14 fun::Fraction< Z >::Fraction ( const Z &  num)
inlineexplicit

Construct a new Fraction object.

Parameters
[in]num

◆ Fraction() [4/4]

template<typename Z >
CONSTEXPR14 fun::Fraction< Z >::Fraction ( )
inline

Construct a new Fraction object (default constructor)

Member Function Documentation

◆ cross()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::cross ( const Fraction< Z > &  rhs) const -> Z
inline

cross product

Parameters
[in]rhs
Returns
Z

◆ den()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::den ( ) const -> const Z&
inlinenoexcept

Get the denominator.

Returns
const Z& Reference to the denominator

◆ normalize()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::normalize ( ) -> Z
inline

normalize to a canonical form

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

◆ normalize1()

template<typename Z >
CONSTEXPR14 void fun::Fraction< Z >::normalize1 ( )
inline

normalize to a canonical form

denominator is always non-negative

◆ normalize2()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::normalize2 ( ) -> Z
inline

normalize to a canonical form

denominator is always co-prime with numerator

◆ num()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::num ( ) const -> const Z&
inlinenoexcept

Get the numerator.

Returns
const Z& Reference to the numerator

◆ operator!=()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator!= ( const Fraction< Z > &  rhs) const -> bool
inline

Not equal to.

Parameters
[in]rhsThe fraction to compare with
Returns
true if the fractions are not equal, false otherwise

◆ operator*=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator*= ( Fraction< Z >  rhs) -> Fraction&
inline

multiply and assign

Parameters
[in]rhs
Returns
Fraction&

◆ operator*=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator*= ( rhs) -> Fraction&
inline

multiply and assign

Parameters
[in]rhs
Returns
Fraction&

◆ operator+()

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator+ ( const Fraction< Z > &  rhs) const -> Fraction
inline

Add.

Parameters
[in]rhs
Returns
Fraction

◆ operator+=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator+= ( const Fraction< Z > &  rhs) -> Fraction&
inline

Add and assign a fraction.

Parameters
[in]rhsThe fraction to add
Returns
Fraction& Reference to this fraction

◆ operator+=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator+= ( const Z &  i) -> Fraction&
inline

Add and assign an integer.

Parameters
[in]iThe integer value to add
Returns
Fraction& Reference to this fraction

◆ operator-() [1/3]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator- ( ) const -> Fraction
inline

Negate.

Returns
Fraction

◆ operator-() [2/3]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator- ( const Fraction< Z > &  frac) const -> Fraction
inline

Subtract.

Parameters
[in]frac
Returns
Fraction

◆ operator-() [3/3]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator- ( const Z &  i) const -> Fraction
inline

Subtract an integer from the fraction.

Parameters
[in]iThe integer value to subtract
Returns
Fraction

◆ operator-=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator-= ( const Fraction< Z > &  rhs) -> Fraction&
inline

Subtract and assign a fraction.

Parameters
[in]rhsThe fraction to subtract
Returns
Fraction& Reference to this fraction

◆ operator-=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator-= ( const Z &  rhs) -> Fraction&
inline

Subtract and assign an integer.

Parameters
[in]rhsThe integer value to subtract
Returns
Fraction& Reference to this fraction

◆ operator/=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator/= ( Fraction< Z >  rhs) -> Fraction&
inline

divide and assign

Parameters
[in]rhs
Returns
Fraction&

◆ operator/=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator/= ( rhs) -> Fraction&
inline

divide and assign

Parameters
[in]rhs
Returns
Fraction&

◆ operator<=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator<= ( const Fraction< Z > &  rhs) const -> bool
inline

Less than or equal to.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ operator<=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator<= ( const Z &  rhs) const -> bool
inline

Less than or equal to.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ operator>() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator> ( const Fraction< Z > &  rhs) const -> bool
inline

Greater than.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ operator>() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator> ( const Z &  rhs) const -> bool
inline

Greater than.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ operator>=() [1/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator>= ( const Fraction< Z > &  rhs) const -> bool
inline

Greater than or euqal to.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ operator>=() [2/2]

template<typename Z >
CONSTEXPR14 auto fun::Fraction< Z >::operator>= ( const Z &  rhs) const -> bool
inline

Greater than or equal to.

Parameters
[in]rhs
Returns
true if the fractions are equal, false otherwise

◆ reciprocal()

template<typename Z >
CONSTEXPR14 void fun::Fraction< Z >::reciprocal ( )
inline

reciprocal

Friends And Related Symbol Documentation

◆ operator* [1/4]

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

multiply

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator* [2/4]

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

multiply

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator* [3/4]

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

multiply

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator* [4/4]

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

Multiply a fraction by an integer rvalue.

Parameters
[in]cThe integer rvalue
[in]fracThe fraction to multiply
Returns
Fraction<Z>

◆ operator+ [1/3]

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

Add.

Parameters
[in]iThe integer value to add
[in]fracThe fraction to add to
Returns
Fraction

◆ operator+ [2/3]

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

Add.

Parameters
[in]fracThe fraction to add to
[in]iThe integer value to add
Returns
Fraction

◆ operator+ [3/3]

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

Add a fraction to an integer rvalue.

Parameters
[in]cThe integer rvalue
[in]fracThe fraction to add
Returns
Fraction

◆ operator- [1/2]

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

Subtract a fraction from an integer.

Parameters
[in]cThe integer value
[in]fracThe fraction to subtract
Returns
Fraction

◆ operator- [2/2]

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

Subtract a fraction from an integer rvalue.

Parameters
[in]cThe integer rvalue
[in]fracThe fraction to subtract
Returns
Fraction

◆ operator/ [1/3]

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

divide

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator/ [2/3]

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

divide

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator/ [3/3]

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

divide

Parameters
[in]lhs
[in]rhs
Returns
Fraction

◆ operator< [1/3]

template<typename Z >
CONSTEXPR14 auto operator< ( const Fraction< Z > &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Less than.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs < rhs, false otherwise

◆ operator< [2/3]

template<typename Z >
CONSTEXPR14 auto operator< ( const Fraction< Z > &  lhs,
const Z &  rhs 
) -> bool
friend

Less than.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs < rhs, false otherwise

◆ operator< [3/3]

template<typename Z >
CONSTEXPR14 auto operator< ( const Z &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Less than.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs < rhs, false otherwise

◆ operator<<

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

Stream output operator for Fraction.

Template Parameters
StreamThe stream type
Parameters
[in]osThe output stream to write to
[in]fracThe fraction to output
Returns
Stream& Reference to the output stream

◆ operator<=

template<typename Z >
CONSTEXPR14 auto operator<= ( const Z &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Less than or equal to.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs <= rhs, false otherwise

◆ operator== [1/3]

template<typename Z >
CONSTEXPR14 auto operator== ( const Fraction< Z > &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Equal to.

Parameters
[in]lhsThe first fraction
[in]rhsThe second fraction
Returns
true if equal, false otherwise

◆ operator== [2/3]

template<typename Z >
CONSTEXPR14 auto operator== ( const Fraction< Z > &  lhs,
const Z &  rhs 
) -> bool
friend

Equal to.

Parameters
[in]lhsThe fraction
[in]rhsThe integer value
Returns
true if equal, false otherwise

◆ operator== [3/3]

template<typename Z >
CONSTEXPR14 auto operator== ( const Z &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Equal to.

Parameters
[in]lhsThe integer value
[in]rhsThe fraction
Returns
true if equal, false otherwise

◆ operator>

template<typename Z >
CONSTEXPR14 auto operator> ( const Z &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Greater than.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs > rhs, false otherwise

◆ operator>=

template<typename Z >
CONSTEXPR14 auto operator>= ( const Z &  lhs,
const Fraction< Z > &  rhs 
) -> bool
friend

Greater than or euqal to.

Parameters
[in]lhs
[in]rhs
Returns
true if lhs >= rhs, false otherwise

Member Data Documentation

◆ _den

template<typename Z >
Z fun::Fraction< Z >::_den

◆ _num

template<typename Z >
Z fun::Fraction< Z >::_num

The documentation for this struct was generated from the following file: