XII Release 0.1.0
Loading...
Searching...
No Matches
xiiRational Class Reference

A class which can be used to represent rational numbers by stating their numerator and denominator. More...

#include <Rational.h>

Public Member Functions

 XII_DECLARE_POD_TYPE ()
 
 xiiRational ()
 Default constructor, initializes to 0/1.
 
 xiiRational (xiiUInt32 uiNumerator, xiiUInt32 uiDenominator)
 Constructor to initialize a rational.
 
bool IsIntegral () const
 returns true if the division of the numerator by the denominator would result in a full integer
 
bool operator== (const xiiRational &other) const
 Equality operator.
 
xiiUInt32 GetNumerator () const
 Returns the numerator of the rational number.
 
xiiUInt32 GetDenominator () const
 Returns the denominator.
 
xiiUInt32 GetIntegralResult () const
 Returns the result of the division as an integer.
 
double GetFloatingPointResult () const
 Returns the result of the division as a floating point number (double).
 
bool IsValid () const
 Returns true if the rational is valid (follows the rules stated in the class description)
 
xiiRational ReduceIntegralFraction () const
 This helper returns a reduced fraction in case of an integral input.
 

Protected Attributes

xiiUInt32 m_uiNumerator = 0
 
xiiUInt32 m_uiDenominator = 1
 

Detailed Description

A class which can be used to represent rational numbers by stating their numerator and denominator.

xiiRational uses the following rules 0/0 is legal and will be interpreted as 0/1 If you are representing a whole number, the denominator should be 1

Member Function Documentation

◆ ReduceIntegralFraction()

XII_ALWAYS_INLINE xiiRational xiiRational::ReduceIntegralFraction ( ) const

This helper returns a reduced fraction in case of an integral input.

Note that this will assert in DEV builds if this class is not integral.


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