Ratio< T > Struct Template Reference
Class to simplify calculations of finite rationals at runtime. More...
#include <Rational.h>
Inheritance diagram for Ratio< T >:
Collaboration diagram for Ratio< T >:
Public Member Functions | |
Ratio ()=default | |
Ratio (const BasicRatio< T > &r) | |
Ratio (T num, T den=1) | |
template<T num, T den> | |
void | set () |
Method template to set ratio and minimise. More... | |
void | set (T num, T den=1) |
Set ratio and minimise. More... | |
template<typename ValueType > | |
operator ValueType () const | |
![]() | |
operator String () const | |
Friends | |
Ratio | operator* (const Ratio &lhs, const Ratio &rhs) |
Evaluate ratio = ratio1 * ratio2 and minimise. More... | |
template<typename ValueType > | |
ValueType | operator* (ValueType lhs, const Ratio &rhs) |
Evaluate value = value * ratio More... | |
template<typename ValueType > | |
ValueType | operator* (const Ratio &lhs, const ValueType &rhs) |
Evaluate value = ratio * value More... | |
Ratio | operator/ (const Ratio &lhs, const Ratio &rhs) |
Evaluate ratio = ratio1 / ratio2 and minimise. More... | |
template<typename ValueType > | |
Ratio | operator/ (Ratio lhs, const ValueType &rhs) |
Evaluate value = Ratio / value More... | |
template<typename ValueType > | |
ValueType | operator/ (ValueType lhs, const Ratio &rhs) |
Evaluate value = value / ratio More... | |
Additional Inherited Members | |
![]() | |
T | num |
T | den |
Detailed Description
template<typename T>
struct Ratio< T >
Class to simplify calculations of finite rationals at runtime.
- Note
- Operations are restricted to multiplication and division using unsigned integer operations. Multiplication and division are rounded to the nearest whole number. Overflows are handled by returning the maximum value rather than truncating.
- Addition and subtraction are not supported directly as this would require overflow detection and probably signed arithmetic, which is slower and limits calculation range.
- See also
- See
muldiv
for further details.
- Note
- Ratio values are minimised in constructor
Constructor & Destructor Documentation
◆ Ratio() [1/3]
◆ Ratio() [2/3]
template<typename T >
|
inline |
◆ Ratio() [3/3]
Member Function Documentation
◆ operator ValueType()
template<typename T >
template<typename ValueType >
|
inlineexplicit |
◆ set() [1/2]
Method template to set ratio and minimise.
- Note
- Use this method where values are known at compile-time
◆ set() [2/2]
template<typename T >
|
inline |
Set ratio and minimise.
- Note
- Use this method for variable ratios
Friends And Related Function Documentation
◆ operator* [1/3]
Evaluate ratio = ratio1 * ratio2
and minimise.
◆ operator* [2/3]
template<typename T >
template<typename ValueType >
|
friend |
Evaluate value = value * ratio
◆ operator* [3/3]
template<typename T >
template<typename ValueType >
|
friend |
Evaluate value = ratio * value
◆ operator/ [1/3]
Evaluate ratio = ratio1 / ratio2
and minimise.
◆ operator/ [2/3]
template<typename T >
template<typename ValueType >
|
friend |
Evaluate value = Ratio / value
◆ operator/ [3/3]
template<typename T >
template<typename ValueType >
|
friend |
Evaluate value = value / ratio
The documentation for this struct was generated from the following file: