PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
pbat::math::Rational Struct Reference

Fixed size rational number \( \frac{a}{b} \) using std::int64_t for numerator and denominator. More...

#include <Rational.h>

Public Member Functions

 Rational ()
 Construct a new Rational object.
 
template<std::integral Integer>
 Rational (Integer _a, Integer _b)
 Construct a new Rational object.
 
template<std::integral Integer>
 Rational (Integer value)
 Construct a new Rational object.
 
Rational operator+ (Rational const &other) const
 Addition operation.
 
Rational operator- (Rational const &other) const
 Subtraction operation.
 
Rational operator- () const
 Negation operation.
 
Rational operator* (Rational const &other) const
 Multiplication operation.
 
Rational operator/ (Rational const &other) const
 Division operation.
 
bool operator== (Rational const &other) const
 Equality operation.
 
bool operator< (Rational const &other) const
 Less-than operation.
 
bool Rebase (std::int64_t denominator)
 Change internal rational representation to have denominator denominator.
 
 operator double () const
 Cast to double.
 
 operator float () const
 Cast to float.
 
void simplify ()
 Attempts to reduce magnitude of \( a,b \) by eliminating common divisor.
 

Public Attributes

std::int64_t a
 Numerator.
 
std::int64_t b
 Denominator.
 

Detailed Description

Fixed size rational number \( \frac{a}{b} \) using std::int64_t for numerator and denominator.

Constructor & Destructor Documentation

◆ Rational() [1/2]

template<std::integral Integer>
pbat::math::Rational::Rational ( Integer _a,
Integer _b )
inline

Construct a new Rational object.

Template Parameters
IntegerIntegral type
Parameters
aNumerator
bDenominator

◆ Rational() [2/2]

template<std::integral Integer>
pbat::math::Rational::Rational ( Integer value)
inline

Construct a new Rational object.

Template Parameters
IntegerIntegral type
Parameters
valueNumerator
Postcondition
Denominator is set to 1

Member Function Documentation

◆ operator double()

pbat::math::Rational::operator double ( ) const
explicit

Cast to double.

Returns

◆ operator float()

pbat::math::Rational::operator float ( ) const
explicit

Cast to float.

Returns

◆ operator*()

Rational pbat::math::Rational::operator* ( Rational const & other) const

Multiplication operation.

Parameters
otherRight-hand side operand
Returns
Result of multiplication

◆ operator+()

Rational pbat::math::Rational::operator+ ( Rational const & other) const

Addition operation.

Parameters
otherRight-hand side operand
Returns
Result of addition

◆ operator-() [1/2]

Rational pbat::math::Rational::operator- ( ) const

Negation operation.

Returns
Result of negation

◆ operator-() [2/2]

Rational pbat::math::Rational::operator- ( Rational const & other) const

Subtraction operation.

Parameters
otherRight-hand side operand
Returns
Result of subtraction

◆ operator/()

Rational pbat::math::Rational::operator/ ( Rational const & other) const

Division operation.

Parameters
otherRight-hand side operand
Returns
Result of division

◆ operator<()

bool pbat::math::Rational::operator< ( Rational const & other) const

Less-than operation.

Parameters
otherRight-hand side operand
Returns
true if not equal

◆ operator==()

bool pbat::math::Rational::operator== ( Rational const & other) const

Equality operation.

Parameters
otherRight-hand side operand
Returns
true if equal

◆ Rebase()

bool pbat::math::Rational::Rebase ( std::int64_t denominator)

Change internal rational representation to have denominator denominator.

Parameters
denominatorNew denominator
Returns
true if successful

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