NTLib - Number Theory Library 0.9
Loading...
Searching...
No Matches
ntlib::rational< T > Class Template Referenceexport
module rational

Represents a rational number. More...

Public Member Functions

 rational (T n, T d=1) noexcept
 Construct rational from a numerator and a denominator.
get_numerator () const noexcept
 Returns the numerator.
get_denominator () const noexcept
 Returns the denominator.
rationaloperator+= (const rational &rhs) noexcept
 Compound assignment addition operator.
rationaloperator-= (const rational &rhs) noexcept
 Compound assignment subtraction operator.
rationaloperator*= (const rational &rhs) noexcept
 Compound assignment multiplication operator.
rationaloperator/= (const rational &rhs) noexcept
 Compound assignment division operator.
 operator bool () const noexcept
 Cast to bool.

Friends

rational operator+ (rational lhs, const rational &rhs) noexcept
 Addition operator.
rational operator- (rational lhs, const rational &rhs) noexcept
 Subtraction operator.
rational operator* (rational lhs, const rational &rhs) noexcept
 Multiplication operator.
rational operator/ (rational lhs, const rational &rhs) noexcept
 Division operator.

Detailed Description

template<Integer T>
class ntlib::rational< T >

Represents a rational number.

Template Parameters
TAn integer-like type.

Constructor & Destructor Documentation

◆ rational()

template<Integer T>
ntlib::rational< T >::rational ( T n,
T d = 1 )
inlinenoexcept

Construct rational from a numerator and a denominator.

This constructor allows implicit conversion from elements of type T.

Parameters
nThe numerator.
dThe denominator. Defaults to 1.

Member Function Documentation

◆ get_denominator()

template<Integer T>
T ntlib::rational< T >::get_denominator ( ) const
inlinenodiscardnoexcept

Returns the denominator.

Returns
The denominator.

◆ get_numerator()

template<Integer T>
T ntlib::rational< T >::get_numerator ( ) const
inlinenodiscardnoexcept

Returns the numerator.

Returns
The numerator.

◆ operator bool()

template<Integer T>
ntlib::rational< T >::operator bool ( ) const
inlineexplicitnodiscardnoexcept

Cast to bool.

Returns
Whether the rational is not equal to zero.

◆ operator*=()

template<Integer T>
rational & ntlib::rational< T >::operator*= ( const rational< T > & rhs)
inlinenoexcept

Compound assignment multiplication operator.

Parameters
rhsThe second factor.
Returns
Reference to the result.

◆ operator+=()

template<Integer T>
rational & ntlib::rational< T >::operator+= ( const rational< T > & rhs)
inlinenoexcept

Compound assignment addition operator.

Parameters
rhsThe second summand.
Returns
Reference to the result.

◆ operator-=()

template<Integer T>
rational & ntlib::rational< T >::operator-= ( const rational< T > & rhs)
inlinenoexcept

Compound assignment subtraction operator.

Parameters
rhsThe subtrahend.
Returns
Reference to the result.

◆ operator/=()

template<Integer T>
rational & ntlib::rational< T >::operator/= ( const rational< T > & rhs)
inlinenoexcept

Compound assignment division operator.

Parameters
rhsThe divisor.
Returns
Reference to the result.

◆ operator*

template<Integer T>
rational operator* ( rational< T > lhs,
const rational< T > & rhs )
friend

Multiplication operator.

Parameters
lhsThe first factor.
rhsThe second factor.
Returns
The product of lhs and rhs.

◆ operator+

template<Integer T>
rational operator+ ( rational< T > lhs,
const rational< T > & rhs )
friend

Addition operator.

Parameters
lhsThe first summand.
rhsThe second summand.
Returns
The sum of lhs and rhs.

◆ operator-

template<Integer T>
rational operator- ( rational< T > lhs,
const rational< T > & rhs )
friend

Subtraction operator.

Parameters
lhsThe minuend.
rhsThe subtrahend.
Returns
The difference of lhs and rhs.

◆ operator/

template<Integer T>
rational operator/ ( rational< T > lhs,
const rational< T > & rhs )
friend

Division operator.

Parameters
lhsThe dividend.
rhsThe divisor.
Returns
The quotient of lhs and rhs.

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