Rational Numbers.
More...
|
| $whole |
|
| $numerator |
|
| $denominator |
|
Rational Numbers.
https://en.wikipedia.org/wiki/Rational_number A rational number can be expressed as a fraction. Using the rational number object allows a user to express non-integer values with exact precision, and perform arithmetic without floating point errors.
◆ __construct()
MathPHP\Number\Rational::__construct |
( |
int |
$w, |
|
|
int |
$n, |
|
|
int |
$d |
|
) |
| |
Constructor.
- Todo:
- How to handle negative numbers in various positions.
- Parameters
-
int | $w | whole part |
int | $n | numerator part |
int | $d | |
◆ __toString()
MathPHP\Number\Rational::__toString |
( |
| ) |
|
String representation of a rational number 5 6/7, 456079/13745859, etc.
- Returns
- string
◆ abs()
MathPHP\Number\Rational::abs |
( |
| ) |
|
The absolute value of a rational number.
- Returns
- Rational
◆ add()
MathPHP\Number\Rational::add |
( |
|
$r | ) |
|
◆ divide()
MathPHP\Number\Rational::divide |
( |
|
$r | ) |
|
Divide Return the result of dividing two rational numbers, or a rational number by an integer.
- Parameters
-
- Returns
- Rational
- Exceptions
-
◆ equals()
MathPHP\Number\Rational::equals |
( |
Rational |
$rn | ) |
|
Test for equality.
Two normalized RationalNumbers are equal IFF all three parts are equal.
- Parameters
-
- Returns
- bool
◆ multiply()
MathPHP\Number\Rational::multiply |
( |
|
$r | ) |
|
◆ subtract()
MathPHP\Number\Rational::subtract |
( |
|
$r | ) |
|
◆ toFloat()
MathPHP\Number\Rational::toFloat |
( |
| ) |
|
Rational number as a float.
- Returns
- float
The documentation for this class was generated from the following file: