public function Fraction::multiply in Fraction 8
Same name and namespace in other branches
- 2.x src/Fraction.php \Drupal\fraction\Fraction::multiply()
Multiplies this fraction with another one.
Parameters
Fraction $fraction: Another fraction object to multiply with.
Return value
Fraction Returns this Fraction object.
Overrides FractionInterface::multiply
File
- src/
Fraction.php, line 327
Class
- Fraction
- A simple class for representing and acting upon a fraction.
Namespace
Drupal\fractionCode
public function multiply(Fraction $fraction) {
// Get the numerator and denominator of each fraction.
$numerator1 = $this
->getNumerator();
$denominator1 = $this
->getDenominator();
$numerator2 = $fraction
->getNumerator();
$denominator2 = $fraction
->getDenominator();
// Calculate the product of the two fractions.
// Use BCMath if available.
if (function_exists('bcmul')) {
$numerator = bcmul($numerator1, $numerator2, 0);
$denominator = bcmul($denominator1, $denominator2, 0);
}
else {
$numerator = $numerator1 * $numerator2;
$denominator = $denominator1 * $denominator2;
}
// Save the numerator and denominator.
$this
->setNumerator($numerator);
$this
->setDenominator($denominator);
return $this;
}