math-php
Public Member Functions | Protected Attributes | List of all members
MathPHP\Number\Rational Class Reference

Rational Numbers. More...

Inheritance diagram for MathPHP\Number\Rational:
Inheritance graph
[legend]
Collaboration diagram for MathPHP\Number\Rational:
Collaboration graph
[legend]

Public Member Functions

 __construct (int $w, int $n, int $d)
 Constructor. More...
 
 __toString ()
 String representation of a rational number 5 6/7, 456079/13745859, etc. More...
 
 toFloat ()
 Rational number as a float. More...
 
 abs ()
 The absolute value of a rational number. More...
 
 add ($r)
 Addition. More...
 
 subtract ($r)
 Subtraction. More...
 
 multiply ($r)
 Multiply Return the result of multiplying two rational numbers, or a rational number and an integer. More...
 
 divide ($r)
 Divide Return the result of dividing two rational numbers, or a rational number by an integer. More...
 
 equals (Rational $rn)
 Test for equality. More...
 

Protected Attributes

 $whole
 
 $numerator
 
 $denominator
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __construct()

MathPHP\Number\Rational::__construct ( int  $w,
int  $n,
int  $d 
)

Constructor.

Todo:
How to handle negative numbers in various positions.
Parameters
int$wwhole part
int$nnumerator part
int$d

Member Function Documentation

◆ __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)

Addition.

Parameters
Rational | int$r
Returns
Rational
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.

◆ divide()

MathPHP\Number\Rational::divide (   $r)

Divide Return the result of dividing two rational numbers, or a rational number by an integer.

Parameters
Rational | int$r
Returns
Rational
Exceptions
Exception

◆ equals()

MathPHP\Number\Rational::equals ( Rational  $rn)

Test for equality.

Two normalized RationalNumbers are equal IFF all three parts are equal.

Parameters
Rational$rn
Returns
bool

◆ multiply()

MathPHP\Number\Rational::multiply (   $r)

Multiply Return the result of multiplying two rational numbers, or a rational number and an integer.

Parameters
Rational | int$r
Returns
Rational
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.

◆ subtract()

MathPHP\Number\Rational::subtract (   $r)

Subtraction.

Parameters
Rational | int$r
Returns
Rational
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.

◆ toFloat()

MathPHP\Number\Rational::toFloat ( )

Rational number as a float.

Returns
float

The documentation for this class was generated from the following file: