numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::numbers::fraction< IntegerType > Class Template Reference

Class of fractions. More...

#include <num_collect/numbers/fraction.h>

+ Collaboration diagram for num_collect::numbers::fraction< IntegerType >:

Public Types

using integer_type = IntegerType
 Type of integers.
 

Public Member Functions

constexpr fraction () noexcept
 Constructor. (Initialize to zero.)
 
constexpr fraction (integer_type integer) noexcept
 Constructor. (Convert from an integer.)
 
constexpr fraction (integer_type numerator, integer_type denominator)
 Constructor.
 
constexpr auto add (const fraction &right) -> fraction &
 Add a fraction to this fraction.
 
constexpr auto denominator () const noexcept -> integer_type
 Get the denominator.
 
constexpr auto divide_by (const fraction &right) -> fraction &
 Divide this fraction by a fraction.
 
constexpr auto inverse () const -> fraction
 Get the inverse of this fraction.
 
constexpr auto multiply (const fraction &right) -> fraction &
 Multiply a fraction to this fraction.
 
constexpr auto numerator () const noexcept -> integer_type
 Get the numerator.
 
constexpr auto operator!= (const fraction &right) const noexcept -> bool
 Compare this fraction with another fraction.
 
constexpr auto operator*= (const fraction &right) -> fraction &
 Multiply a fraction to this fraction.
 
constexpr auto operator+= (const fraction &right) -> fraction &
 Add a fraction to this fraction.
 
constexpr auto operator-= (const fraction &right) -> fraction &
 Subtract a fraction from this fraction.
 
constexpr auto operator/= (const fraction &right) -> fraction &
 Divide this fraction by a fraction.
 
constexpr auto operator== (const fraction &right) const noexcept -> bool
 Compare this fraction with another fraction.
 
constexpr auto subtract (const fraction &right) -> fraction &
 Subtract a fraction from this fraction.
 

Private Member Functions

constexpr void normalize ()
 Normalize this fraction.
 

Static Private Member Functions

static constexpr auto int_abs (integer_type x) noexcept -> integer_type
 Get the absolute value of an integer.
 

Private Attributes

integer_type denominator_
 Denominator.
 
integer_type numerator_
 Numerator.
 

Detailed Description

template<base::concepts::integral IntegerType>
class num_collect::numbers::fraction< IntegerType >

Class of fractions.

Template Parameters
IntegerTypeType of integers.

Definition at line 43 of file fraction.h.

Member Typedef Documentation

◆ integer_type

template<base::concepts::integral IntegerType>
using num_collect::numbers::fraction< IntegerType >::integer_type = IntegerType

Type of integers.

Definition at line 46 of file fraction.h.

Constructor & Destructor Documentation

◆ fraction() [1/3]

template<base::concepts::integral IntegerType>
num_collect::numbers::fraction< IntegerType >::fraction ( integer_type numerator,
integer_type denominator )
inlineconstexpr

Constructor.

Parameters
[in]numeratorNumerator.
[in]denominatorDenominator.

Definition at line 54 of file fraction.h.

◆ fraction() [2/3]

template<base::concepts::integral IntegerType>
num_collect::numbers::fraction< IntegerType >::fraction ( integer_type integer)
inlineconstexprnoexcept

Constructor. (Convert from an integer.)

Parameters
[in]integerInteger.

Definition at line 66 of file fraction.h.

◆ fraction() [3/3]

template<base::concepts::integral IntegerType>
num_collect::numbers::fraction< IntegerType >::fraction ( )
inlineconstexprnoexcept

Constructor. (Initialize to zero.)

Definition at line 73 of file fraction.h.

Member Function Documentation

◆ add()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::add ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Add a fraction to this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after addition.

Definition at line 110 of file fraction.h.

◆ denominator()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::denominator ( ) const -> integer_type
inlinenodiscardconstexprnoexcept

Get the denominator.

Returns
Denominator.

Definition at line 89 of file fraction.h.

◆ divide_by()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::divide_by ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Divide this fraction by a fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after division.

Definition at line 208 of file fraction.h.

◆ int_abs()

template<base::concepts::integral IntegerType>
static constexpr auto num_collect::numbers::fraction< IntegerType >::int_abs ( integer_type x) -> integer_type
inlinestaticconstexprprivatenoexcept

Get the absolute value of an integer.

Parameters
[in]xInteger.
Returns
Absolute value.

Definition at line 275 of file fraction.h.

◆ inverse()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::inverse ( ) const -> fraction
inlinenodiscardconstexpr

Get the inverse of this fraction.

Returns
Inverse.

Definition at line 218 of file fraction.h.

◆ multiply()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::multiply ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Multiply a fraction to this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after multiplication.

Definition at line 184 of file fraction.h.

◆ normalize()

template<base::concepts::integral IntegerType>
void num_collect::numbers::fraction< IntegerType >::normalize ( )
inlineconstexprprivate

Normalize this fraction.

Definition at line 250 of file fraction.h.

◆ numerator()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::numerator ( ) const -> integer_type
inlinenodiscardconstexprnoexcept

Get the numerator.

Returns
Numerator.

Definition at line 80 of file fraction.h.

◆ operator!=()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator!= ( const fraction< IntegerType > & right) const -> bool
inlineconstexprnoexcept

Compare this fraction with another fraction.

Parameters
[in]rightRight-hand-side object.
Return values
trueThis fraction is different from the given fraction.
falseThis fraction is same with the given fraction.

Definition at line 242 of file fraction.h.

◆ operator*=()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator*= ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Multiply a fraction to this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after multiplication.

Definition at line 173 of file fraction.h.

◆ operator+=()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator+= ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Add a fraction to this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after addition.

Definition at line 99 of file fraction.h.

◆ operator-=()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator-= ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Subtract a fraction from this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after subtraction.

Definition at line 136 of file fraction.h.

◆ operator/=()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator/= ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Divide this fraction by a fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after division.

Definition at line 197 of file fraction.h.

◆ operator==()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::operator== ( const fraction< IntegerType > & right) const -> bool
inlineconstexprnoexcept

Compare this fraction with another fraction.

Parameters
[in]rightRight-hand-side object.
Return values
trueThis fraction is same with the given fraction.
falseThis fraction is different from the given fraction.

Definition at line 229 of file fraction.h.

◆ subtract()

template<base::concepts::integral IntegerType>
auto num_collect::numbers::fraction< IntegerType >::subtract ( const fraction< IntegerType > & right) -> fraction&
inlineconstexpr

Subtract a fraction from this fraction.

Parameters
[in]rightRight-hand-side object.
Returns
This fraction after subtraction.

Definition at line 147 of file fraction.h.

Member Data Documentation

◆ denominator_

template<base::concepts::integral IntegerType>
integer_type num_collect::numbers::fraction< IntegerType >::denominator_
private

Denominator.

Definition at line 291 of file fraction.h.

◆ numerator_

template<base::concepts::integral IntegerType>
integer_type num_collect::numbers::fraction< IntegerType >::numerator_
private

Numerator.

Definition at line 288 of file fraction.h.


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