Implementation of rational number arithmetic.
More...
|
| $p |
| int $p numerator
|
|
| $q |
| int $q denominator
|
|
Implementation of rational number arithmetic.
Example:
$a = new Rational(1, 4);
$b = new Rational(2, 3);
MathParser\Extensions\Rational::__construct |
( |
|
$p, |
|
|
|
$q, |
|
|
|
$normalize = true |
|
) |
| |
Constuctor for Rational number class.
$r = new Rational(2, 4) // creates 1/2 $r = new Rational(2, 4, false) // creates 2/4
- Parameters
-
int | $p | numerator |
int | $q | denominator |
bool | $normalize | (default true) If true, store in normalized form, i.e. positive denominator and gcd($p, $q) = 1 |
MathParser\Extensions\Rational::__toString |
( |
| ) |
|
Convert Rational to string.
- Return values
-
static MathParser\Extensions\Rational::add |
( |
|
$x, |
|
|
|
$y |
|
) |
| |
|
static |
add two rational numbers
Rational::add($x, $y) computes and returns $x+$y
- Parameters
-
- Return values
-
static MathParser\Extensions\Rational::div |
( |
|
$x, |
|
|
|
$y |
|
) |
| |
|
static |
add two rational numbers
Rational::div($x, $y) computes and returns $x/$y
- Parameters
-
- Return values
-
static MathParser\Extensions\Rational::fromFloat |
( |
|
$float, |
|
|
|
$tolerance = 1e-7 |
|
) |
| |
|
static |
convert float to Rational
Convert float to a continued fraction, with prescribed accuracy
- Parameters
-
string | float | $float | |
float | $tolerance | |
- Return values
-
MathParser\Extensions\Rational::is_nan |
( |
| ) |
|
test if the rational number is NAN
- Return values
-
static MathParser\Extensions\Rational::isInteger |
( |
|
$value | ) |
|
|
staticprivate |
test whether a string represents an positive integer
- Return values
-
static MathParser\Extensions\Rational::isSignedInteger |
( |
|
$value | ) |
|
|
staticprivate |
test whether a string represents a signed integer
- Return values
-
static MathParser\Extensions\Rational::mul |
( |
|
$x, |
|
|
|
$y |
|
) |
| |
|
static |
multiply two rational numbers
Rational::mul($x, $y) computes and returns $x*$y
- Parameters
-
- Return values
-
MathParser\Extensions\Rational::normalize |
( |
| ) |
|
|
private |
Normalize, i.e.
make sure the denominator is positive and that the numerator and denominator have no common factors
static MathParser\Extensions\Rational::parse |
( |
|
$value, |
|
|
|
$normalize = true |
|
) |
| |
|
static |
Convert $value to Rational.
- Parameters
-
- Exceptions
-
- Return values
-
MathParser\Extensions\Rational::signed |
( |
| ) |
|
convert rational number to string, adding a '+' if the number is positive
- Return values
-
static MathParser\Extensions\Rational::sub |
( |
|
$x, |
|
|
|
$y |
|
) |
| |
|
static |
subtract two rational numbers
Rational::sub($x, $y) computes and returns $x-$y
- Parameters
-
- Return values
-
The documentation for this class was generated from the following file:
- src/MathParser/Extensions/Rational.php