C++ Library Extensions 2022.12.09
To help learn modern C++ programming
cpg::rational_number::rational< ElementType > Class Template Reference

#include <cpg_rational.hpp>

Collaboration diagram for cpg::rational_number::rational< ElementType >:
[legend]

Public Types

using value_type = ElementType
 

Public Member Functions

constexpr void reduce () noexcept
 
constexpr rational () noexcept=default
 
constexpr rational (ElementType numerator) noexcept
 
constexpr rational (ElementType numerator, ElementType denominator, bool DoNotReduce=false) noexcept
 
constexpr rational abs () const noexcept
 
template<typename Type = ElementType>
Type mag () const noexcept
 
template<typename Type = ElementType>
Type abs_mag () const noexcept
 
constexpr ~rational ()
 
constexpr bool valid () const noexcept
 
constexpr operator bool () const noexcept
 
constexpr bool operator! () const noexcept
 
constexpr const ElementType & num () const noexcept
 
constexpr const ElementType & den () const noexcept
 
constexpr ElementType num (ElementType new_value, bool DoNotReduce=false) noexcept
 
constexpr ElementType den (ElementType new_value, bool DoNotReduce=false) noexcept
 
constexpr rational operator() (ElementType numerator, ElementType denominator, bool DoNotReduce=false) noexcept
 
constexpr void set (ElementType numerator, ElementType denominator, bool DoNotReduce=false) noexcept
 
constexpr const rationaloperator++ () noexcept
 
constexpr const rationaloperator-- () noexcept
 
constexpr rational operator++ (int) noexcept
 
constexpr rational operator-- (int) noexcept
 
template<number_c Type = long long>
constexpr operator Type () const noexcept
 
template<allowed_type_c TargetType = ElementType, real_number_c RoundType = long double>
TargetType round () const noexcept
 
constexpr rational reciprocal () const noexcept
 
constexpr rationaloperator*= (const rational &rhs) noexcept
 
constexpr rationaloperator/= (const rational &rhs) noexcept
 
constexpr rationaloperator*= (ElementType rhs) noexcept
 
constexpr rationaloperator/= (ElementType rhs) noexcept
 
constexpr rational inverse () const noexcept
 
constexpr rational operator- () const noexcept
 
constexpr rationaloperator+= (const rational &rhs) noexcept
 
constexpr rationaloperator-= (const rational &rhs) noexcept
 
constexpr rationaloperator+= (ElementType rhs) noexcept
 
constexpr rationaloperator-= (ElementType rhs) noexcept
 

Public Attributes

ElementType m_num = 0
 
ElementType m_den = 1
 

Friends

constexpr std::strong_ordering operator<=> (const rational &lhs, const rational &rhs)
 
constexpr std::strong_ordering operator<=> (const rational &lhs, ElementType rhs) noexcept
 
constexpr bool operator== (const rational &lhs, const rational &rhs) noexcept
 
constexpr bool operator== (const rational &lhs, ElementType rhs) noexcept
 
constexpr rational operator* (ElementType lhs, rational rhs) noexcept
 
constexpr rational operator* (rational lhs, ElementType rhs) noexcept
 
constexpr rational operator/ (ElementType lhs, const rational &rhs) noexcept
 
constexpr rational operator/ (const rational &lhs, ElementType rhs) noexcept
 
constexpr rational operator* (rational lhs, const rational &rhs) noexcept
 
constexpr rational operator/ (rational lhs, const rational &rhs) noexcept
 
constexpr rational operator+ (rational lhs, const rational &rhs) noexcept
 
constexpr rational operator- (rational lhs, const rational &rhs) noexcept
 
constexpr rational operator+ (ElementType lhs, rational rhs) noexcept
 
constexpr rational operator- (ElementType lhs, const rational &rhs) noexcept
 
constexpr rational operator+ (rational lhs, ElementType rhs) noexcept
 
constexpr rational operator- (rational lhs, ElementType rhs) noexcept
 
template<typename CharType >
std::basic_ostream< CharType > & operator<< (std::basic_ostream< CharType > &os, const rational &r) noexcept
 

Detailed Description

template<allowed_type_c ElementType>
class cpg::rational_number::rational< ElementType >

Definition at line 127 of file cpg_rational.hpp.

Member Typedef Documentation

◆ value_type

template<allowed_type_c ElementType>
using cpg::rational_number::rational< ElementType >::value_type = ElementType

Definition at line 131 of file cpg_rational.hpp.

Constructor & Destructor Documentation

◆ rational() [1/3]

template<allowed_type_c ElementType>
constexpr cpg::rational_number::rational< ElementType >::rational ( )
constexprdefaultnoexcept

◆ rational() [2/3]

template<allowed_type_c ElementType>
constexpr cpg::rational_number::rational< ElementType >::rational ( ElementType  numerator)
inlineexplicitconstexprnoexcept

Definition at line 144 of file cpg_rational.hpp.

◆ rational() [3/3]

template<allowed_type_c ElementType>
constexpr cpg::rational_number::rational< ElementType >::rational ( ElementType  numerator,
ElementType  denominator,
bool  DoNotReduce = false 
)
inlineconstexprnoexcept

Definition at line 147 of file cpg_rational.hpp.

◆ ~rational()

template<allowed_type_c ElementType>
constexpr cpg::rational_number::rational< ElementType >::~rational ( )
inlineconstexpr

Definition at line 193 of file cpg_rational.hpp.

Member Function Documentation

◆ abs()

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::abs ( ) const
inlineconstexprnoexcept

Definition at line 155 of file cpg_rational.hpp.

◆ abs_mag()

template<allowed_type_c ElementType>
template<typename Type = ElementType>
Type cpg::rational_number::rational< ElementType >::abs_mag ( ) const
inlinenoexcept

Definition at line 178 of file cpg_rational.hpp.

◆ den() [1/2]

template<allowed_type_c ElementType>
constexpr const ElementType & cpg::rational_number::rational< ElementType >::den ( ) const
inlineconstexprnoexcept

Definition at line 221 of file cpg_rational.hpp.

◆ den() [2/2]

template<allowed_type_c ElementType>
constexpr ElementType cpg::rational_number::rational< ElementType >::den ( ElementType  new_value,
bool  DoNotReduce = false 
)
inlineconstexprnoexcept

Definition at line 241 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ inverse()

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::inverse ( ) const
inlineconstexprnoexcept

Definition at line 523 of file cpg_rational.hpp.

◆ mag()

template<allowed_type_c ElementType>
template<typename Type = ElementType>
Type cpg::rational_number::rational< ElementType >::mag ( ) const
inlinenoexcept

Definition at line 162 of file cpg_rational.hpp.

◆ num() [1/2]

template<allowed_type_c ElementType>
constexpr const ElementType & cpg::rational_number::rational< ElementType >::num ( ) const
inlineconstexprnoexcept

Definition at line 215 of file cpg_rational.hpp.

◆ num() [2/2]

template<allowed_type_c ElementType>
constexpr ElementType cpg::rational_number::rational< ElementType >::num ( ElementType  new_value,
bool  DoNotReduce = false 
)
inlineconstexprnoexcept

Definition at line 228 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator bool()

template<allowed_type_c ElementType>
constexpr cpg::rational_number::rational< ElementType >::operator bool ( ) const
inlineconstexprnoexcept

Definition at line 203 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator Type()

template<allowed_type_c ElementType>
template<number_c Type = long long>
constexpr cpg::rational_number::rational< ElementType >::operator Type ( ) const
inlineconstexprnoexcept

Definition at line 315 of file cpg_rational.hpp.

◆ operator!()

template<allowed_type_c ElementType>
constexpr bool cpg::rational_number::rational< ElementType >::operator! ( ) const
inlineconstexprnoexcept

Definition at line 209 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator()()

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::operator() ( ElementType  numerator,
ElementType  denominator,
bool  DoNotReduce = false 
)
inlineconstexprnoexcept

Definition at line 254 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator*=() [1/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator*= ( const rational< ElementType > &  rhs)
inlineconstexprnoexcept

Definition at line 423 of file cpg_rational.hpp.

◆ operator*=() [2/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator*= ( ElementType  rhs)
inlineconstexprnoexcept

Definition at line 445 of file cpg_rational.hpp.

◆ operator++() [1/2]

template<allowed_type_c ElementType>
constexpr const rational & cpg::rational_number::rational< ElementType >::operator++ ( )
inlineconstexprnoexcept

Definition at line 281 of file cpg_rational.hpp.

◆ operator++() [2/2]

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::operator++ ( int  )
inlineconstexprnoexcept

Definition at line 297 of file cpg_rational.hpp.

◆ operator+=() [1/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator+= ( const rational< ElementType > &  rhs)
inlineconstexprnoexcept

Definition at line 534 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator+=() [2/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator+= ( ElementType  rhs)
inlineconstexprnoexcept

Definition at line 615 of file cpg_rational.hpp.

◆ operator-()

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::operator- ( ) const
inlineconstexprnoexcept

Definition at line 529 of file cpg_rational.hpp.

◆ operator--() [1/2]

template<allowed_type_c ElementType>
constexpr const rational & cpg::rational_number::rational< ElementType >::operator-- ( )
inlineconstexprnoexcept

Definition at line 289 of file cpg_rational.hpp.

◆ operator--() [2/2]

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::operator-- ( int  )
inlineconstexprnoexcept

Definition at line 307 of file cpg_rational.hpp.

◆ operator-=() [1/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator-= ( const rational< ElementType > &  rhs)
inlineconstexprnoexcept

Definition at line 568 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator-=() [2/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator-= ( ElementType  rhs)
inlineconstexprnoexcept

Definition at line 634 of file cpg_rational.hpp.

◆ operator/=() [1/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator/= ( const rational< ElementType > &  rhs)
inlineconstexprnoexcept

Definition at line 440 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ operator/=() [2/2]

template<allowed_type_c ElementType>
constexpr rational & cpg::rational_number::rational< ElementType >::operator/= ( ElementType  rhs)
inlineconstexprnoexcept

Definition at line 472 of file cpg_rational.hpp.

◆ reciprocal()

template<allowed_type_c ElementType>
constexpr rational cpg::rational_number::rational< ElementType >::reciprocal ( ) const
inlineconstexprnoexcept

Definition at line 402 of file cpg_rational.hpp.

Here is the caller graph for this function:

◆ reduce()

template<allowed_type_c ElementType>
constexpr void cpg::rational_number::rational< ElementType >::reduce ( )
inlineconstexprnoexcept

Definition at line 136 of file cpg_rational.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ round()

template<allowed_type_c ElementType>
template<allowed_type_c TargetType = ElementType, real_number_c RoundType = long double>
TargetType cpg::rational_number::rational< ElementType >::round ( ) const
inlinenoexcept

Definition at line 322 of file cpg_rational.hpp.

◆ set()

template<allowed_type_c ElementType>
constexpr void cpg::rational_number::rational< ElementType >::set ( ElementType  numerator,
ElementType  denominator,
bool  DoNotReduce = false 
)
inlineconstexprnoexcept

Definition at line 268 of file cpg_rational.hpp.

Here is the call graph for this function:

◆ valid()

template<allowed_type_c ElementType>
constexpr bool cpg::rational_number::rational< ElementType >::valid ( ) const
inlineconstexprnoexcept

Definition at line 197 of file cpg_rational.hpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator* [1/3]

template<allowed_type_c ElementType>
constexpr rational operator* ( ElementType  lhs,
rational< ElementType >  rhs 
)
friend

Definition at line 461 of file cpg_rational.hpp.

◆ operator* [2/3]

template<allowed_type_c ElementType>
constexpr rational operator* ( rational< ElementType >  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 509 of file cpg_rational.hpp.

◆ operator* [3/3]

template<allowed_type_c ElementType>
constexpr rational operator* ( rational< ElementType >  lhs,
ElementType  rhs 
)
friend

Definition at line 467 of file cpg_rational.hpp.

◆ operator+ [1/3]

template<allowed_type_c ElementType>
constexpr rational operator+ ( ElementType  lhs,
rational< ElementType >  rhs 
)
friend

Definition at line 654 of file cpg_rational.hpp.

◆ operator+ [2/3]

template<allowed_type_c ElementType>
constexpr rational operator+ ( rational< ElementType >  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 604 of file cpg_rational.hpp.

◆ operator+ [3/3]

template<allowed_type_c ElementType>
constexpr rational operator+ ( rational< ElementType >  lhs,
ElementType  rhs 
)
friend

Definition at line 674 of file cpg_rational.hpp.

◆ operator- [1/3]

template<allowed_type_c ElementType>
constexpr rational operator- ( ElementType  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 660 of file cpg_rational.hpp.

◆ operator- [2/3]

template<allowed_type_c ElementType>
constexpr rational operator- ( rational< ElementType >  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 610 of file cpg_rational.hpp.

◆ operator- [3/3]

template<allowed_type_c ElementType>
constexpr rational operator- ( rational< ElementType >  lhs,
ElementType  rhs 
)
friend

Definition at line 680 of file cpg_rational.hpp.

◆ operator/ [1/3]

template<allowed_type_c ElementType>
constexpr rational operator/ ( const rational< ElementType > &  lhs,
ElementType  rhs 
)
friend

Definition at line 494 of file cpg_rational.hpp.

◆ operator/ [2/3]

template<allowed_type_c ElementType>
constexpr rational operator/ ( ElementType  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 487 of file cpg_rational.hpp.

◆ operator/ [3/3]

template<allowed_type_c ElementType>
constexpr rational operator/ ( rational< ElementType >  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 515 of file cpg_rational.hpp.

◆ operator<<

template<allowed_type_c ElementType>
template<typename CharType >
std::basic_ostream< CharType > & operator<< ( std::basic_ostream< CharType > &  os,
const rational< ElementType > &  r 
)
friend

Definition at line 686 of file cpg_rational.hpp.

◆ operator<=> [1/2]

template<allowed_type_c ElementType>
constexpr std::strong_ordering operator<=> ( const rational< ElementType > &  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 328 of file cpg_rational.hpp.

◆ operator<=> [2/2]

template<allowed_type_c ElementType>
constexpr std::strong_ordering operator<=> ( const rational< ElementType > &  lhs,
ElementType  rhs 
)
friend

Definition at line 378 of file cpg_rational.hpp.

◆ operator== [1/2]

template<allowed_type_c ElementType>
constexpr bool operator== ( const rational< ElementType > &  lhs,
const rational< ElementType > &  rhs 
)
friend

Definition at line 384 of file cpg_rational.hpp.

◆ operator== [2/2]

template<allowed_type_c ElementType>
constexpr bool operator== ( const rational< ElementType > &  lhs,
ElementType  rhs 
)
friend

Definition at line 393 of file cpg_rational.hpp.

Member Data Documentation

◆ m_den

template<allowed_type_c ElementType>
ElementType cpg::rational_number::rational< ElementType >::m_den = 1

Definition at line 134 of file cpg_rational.hpp.

◆ m_num

template<allowed_type_c ElementType>
ElementType cpg::rational_number::rational< ElementType >::m_num = 0

Definition at line 133 of file cpg_rational.hpp.


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