The rational utility functions allow easy manipulation of rational numbers.
Add 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.
- Parameters
-
a | First operand |
b | Second operand |
- Returns
- a + b
Divide 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.
- Parameters
-
a | First operand |
b | Second operand |
- Returns
- a / b
Test 2 rational numbers for equality.
- Parameters
-
a | First operand |
b | Second operand |
- Returns
- true if equal
Convert a signed 32-bit Q16 number to a rational number.
- Parameters
-
fixed | Signed 32-bit Q16 number to convert |
- Returns
- Rational number
Multiply 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.
- Parameters
-
a | First operand |
b | Second operand |
- Returns
- a * b
Reduce a rational number to it's simplest form.
- Parameters
-
rational | Rational number to simplify |
Subtract 2 rational numbers. It is assumed that both input rational numbers are in their simplest form.
- Parameters
-
a | First operand |
b | Second operand |
- Returns
- a - b
Convert a rational number to a 32-bit signed Q16 number. Saturation will occur for rational numbers with an absolute value greater than 32768.
- Parameters
-
rational | Rational number to convert |
- Returns
- 32-bit signed Q16 number