C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
essence::rational Struct Reference

Represents a rational number consisting of its corresponding numerator and denominator. More...

#include <rational.hpp>

Public Member Functions

constexpr rational (const rational &)=default
 
constexpr rational (rational &&) noexcept=default
 
constexpr rational (std::int64_t numerator) noexcept
 
constexpr rational (std::int64_t numerator, std::int64_t denominator) noexcept
 
template<typename T >
requires (std::is_aggregate_v<std::decay_t<T>> && similar_rational<std::decay_t<T>>)
constexpr rational (T &&obj) noexcept
 
rationaloperator= (const rational &)=default
 
rationaloperator= (rational &&) noexcept=default
 
template<typename T >
requires similar_rational<std::decay_t<T>>
constexpr operator T () const noexcept(similar_rational< std::decay_t< T > >)
 Converts to a similar object.
 
template<std::floating_point T>
constexpr operator T () const noexcept
 Converts to a floating-point number.
 
constexpr void simplify () noexcept
 
constexpr rational reciprocal () const noexcept
 Gets the reciprocal of the rational.
 
constexpr bool operator< (const rational &right) const noexcept
 
constexpr bool operator> (const rational &right) const noexcept
 
constexpr bool operator== (const rational &right) const noexcept
 
constexpr bool operator!= (const rational &right) const noexcept
 
constexpr bool operator<= (const rational &right) const noexcept
 
constexpr bool operator>= (const rational &right) const noexcept
 

Public Attributes

std::int64_t numerator {}
 
std::int64_t denominator {}
 

Friends

constexpr rational operator- (const rational &value) noexcept
 
constexpr rational operator+ (const rational &left, const rational &right) noexcept
 
constexpr rational operator- (const rational &left, const rational &right) noexcept
 
constexpr rational operator* (const rational &left, const rational &right) noexcept
 
constexpr rational operator/ (const rational &left, const rational &right) noexcept
 

Detailed Description

Represents a rational number consisting of its corresponding numerator and denominator.

Member Function Documentation

◆ operator T() [1/2]

template<std::floating_point T>
essence::rational::operator T ( ) const
inlineexplicitconstexprnoexcept

Converts to a floating-point number.

Template Parameters
TThe type of the floating-point number.

◆ operator T() [2/2]

template<typename T >
requires similar_rational<std::decay_t<T>>
essence::rational::operator T ( ) const
inlineconstexprnoexcept

Converts to a similar object.

Template Parameters
TThe type of the similar object.

◆ reciprocal()

rational essence::rational::reciprocal ( ) const
inlinenodiscardconstexprnoexcept

Gets the reciprocal of the rational.

Returns
The reciprocal.

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