Monado OpenXR Runtime
xrt::auxiliary::math::Rational< Scalar > Struct Template Reference

A rational (fractional) number type. More...

#include <math/m_rational.hpp>

Collaboration diagram for xrt::auxiliary::math::Rational< Scalar >:

Public Types

using value_type = Scalar
 

Public Member Functions

constexpr Rational reciprocal () const noexcept
 Return the reciprocal of this value. More...
 
constexpr Rational withNonNegativeDenominator () const noexcept
 Return this value, with the denominator non-negative (0 or positive). More...
 
constexpr bool isOverUnity () const noexcept
 Does this rational number represent a value greater than 1, with a positive denominator? More...
 
constexpr bool isUnity () const noexcept
 Does this rational number represent 1? More...
 
constexpr bool isZero () const noexcept
 Does this rational number represent 0? More...
 
constexpr bool isBetweenZeroAndOne () const noexcept
 Does this rational number represent a value between 0 and 1 (exclusive), and has a positive denominator? More...
 
constexpr Rational complement () const noexcept
 Get the complementary fraction. More...
 
constexpr float as_float () const noexcept
 Get an approximation of this value as a float. More...
 
constexpr double as_double () const noexcept
 Get an approximation of this value as a double. More...
 

Static Public Member Functions

static constexpr Rational< ScalarsimplestUnity () noexcept
 Return the rational value 1/1, the simplest unity (== 1) value. More...
 

Data Fields

value_type numerator
 
value_type denominator
 

Related Functions

(Note that these are not member functions.)

template<typename Scalar >
constexpr Rational< Scalaroperator* (const Rational< Scalar > &lhs, const Rational< Scalar > &rhs)
 Multiplication operator. More...
 
template<typename Scalar >
constexpr Rational< Scalaroperator* (const Rational< Scalar > &lhs, const Scalar &rhs)
 Multiplication operator with a scalar. More...
 
template<typename Scalar >
constexpr Rational< Scalaroperator* (const Scalar &lhs, const Rational< Scalar > &rhs)
 Multiplication operator with a scalar. More...
 
template<typename Scalar >
constexpr bool operator== (const Rational< Scalar > &lhs, const Rational< Scalar > &rhs)
 Equality comparison operator. More...
 
template<typename Scalar >
constexpr Rational< Scalaroperator/ (const Rational< Scalar > &lhs, const Rational< Scalar > &rhs)
 Division operator. More...
 
template<typename Scalar >
constexpr Rational< Scalaroperator/ (const Rational< Scalar > &lhs, Scalar rhs)
 Division operator by a scalar. More...
 

Detailed Description

template<typename Scalar>
struct xrt::auxiliary::math::Rational< Scalar >

A rational (fractional) number type.

Member Function Documentation

◆ as_double()

template<typename Scalar >
constexpr double xrt::auxiliary::math::Rational< Scalar >::as_double ( ) const
inlineconstexprnoexcept

Get an approximation of this value as a double.

◆ as_float()

template<typename Scalar >
constexpr float xrt::auxiliary::math::Rational< Scalar >::as_float ( ) const
inlineconstexprnoexcept

Get an approximation of this value as a float.

◆ complement()

template<typename Scalar >
constexpr Rational xrt::auxiliary::math::Rational< Scalar >::complement ( ) const
inlineconstexprnoexcept

Get the complementary fraction.

Only really makes sense if isBetweenZeroAndOne() is true

Result will have a non-negative denominator.

◆ isBetweenZeroAndOne()

template<typename Scalar >
constexpr bool xrt::auxiliary::math::Rational< Scalar >::isBetweenZeroAndOne ( ) const
inlineconstexprnoexcept

Does this rational number represent a value between 0 and 1 (exclusive), and has a positive denominator?

This is the most common useful range.

◆ isOverUnity()

template<typename Scalar >
constexpr bool xrt::auxiliary::math::Rational< Scalar >::isOverUnity ( ) const
inlineconstexprnoexcept

Does this rational number represent a value greater than 1, with a positive denominator?

◆ isUnity()

template<typename Scalar >
constexpr bool xrt::auxiliary::math::Rational< Scalar >::isUnity ( ) const
inlineconstexprnoexcept

Does this rational number represent 1?

Note
false if denominator is 0, even if numerator is also 0.

◆ isZero()

template<typename Scalar >
constexpr bool xrt::auxiliary::math::Rational< Scalar >::isZero ( ) const
inlineconstexprnoexcept

Does this rational number represent 0?

Note
false if denominator is 0, even if numerator is also 0.

◆ reciprocal()

template<typename Scalar >
constexpr Rational xrt::auxiliary::math::Rational< Scalar >::reciprocal ( ) const
inlineconstexprnoexcept

Return the reciprocal of this value.

Result will have a non-negative denominator.

Referenced by xrt::auxiliary::math::Rational< Scalar >::operator/().

◆ simplestUnity()

template<typename Scalar >
static constexpr Rational< Scalar > xrt::auxiliary::math::Rational< Scalar >::simplestUnity ( )
inlinestaticconstexprnoexcept

Return the rational value 1/1, the simplest unity (== 1) value.

◆ withNonNegativeDenominator()

template<typename Scalar >
constexpr Rational xrt::auxiliary::math::Rational< Scalar >::withNonNegativeDenominator ( ) const
inlineconstexprnoexcept

Return this value, with the denominator non-negative (0 or positive).

Friends And Related Function Documentation

◆ operator*() [1/3]

template<typename Scalar >
constexpr Rational< Scalar > operator* ( const Rational< Scalar > &  lhs,
const Rational< Scalar > &  rhs 
)
related

Multiplication operator.

Warning: does no simplification!

Result will have a non-negative denominator.

◆ operator*() [2/3]

template<typename Scalar >
constexpr Rational< Scalar > operator* ( const Rational< Scalar > &  lhs,
const Scalar rhs 
)
related

Multiplication operator with a scalar.

Warning: does no simplification!

Result will have a non-negative denominator.

◆ operator*() [3/3]

template<typename Scalar >
constexpr Rational< Scalar > operator* ( const Scalar lhs,
const Rational< Scalar > &  rhs 
)
related

Multiplication operator with a scalar.

Warning: does no simplification!

Result will have a non-negative denominator.

◆ operator/() [1/2]

template<typename Scalar >
constexpr Rational< Scalar > operator/ ( const Rational< Scalar > &  lhs,
const Rational< Scalar > &  rhs 
)
related

Division operator.

Warning: does no simplification!

Result will have a non-negative denominator.

References xrt::auxiliary::math::Rational< Scalar >::reciprocal().

◆ operator/() [2/2]

template<typename Scalar >
constexpr Rational< Scalar > operator/ ( const Rational< Scalar > &  lhs,
Scalar  rhs 
)
related

Division operator by a scalar.

Warning: does no simplification!

Result will have a non-negative denominator.

◆ operator==()

template<typename Scalar >
constexpr bool operator== ( const Rational< Scalar > &  lhs,
const Rational< Scalar > &  rhs 
)
related

Equality comparison operator.

Warning: does no simplification, looks for exact equality!


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