Plasma Engine  2.0
Loading...
Searching...
No Matches
plRational 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

 PL_DECLARE_POD_TYPE ()
 
 plRational ()
 Default constructor, initializes to 0/1.
 
 plRational (plUInt32 uiNumerator, plUInt32 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 plRational &other) const
 Equality operator.
 
bool operator!= (const plRational &other) const
 Inequality operator.
 
plUInt32 GetNumerator () const
 Returns the numerator of the rational number.
 
plUInt32 GetDenominator () const
 Returns the denominator.
 
plUInt32 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)
 
plRational ReduceIntegralFraction () const
 This helper returns a reduced fraction in case of an integral input.
 

Protected Attributes

plUInt32 m_uiNumerator = 0
 
plUInt32 m_uiDenominator = 1
 

Detailed Description

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

plRational 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()

PL_ALWAYS_INLINE plRational plRational::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: