Skip to content

Commit f252335

Browse files
committed
#17: bug fix: Fraction::toCommonDenominator()
cheking if denominators are not null nor zero has been implemented.
1 parent 36ca9f6 commit f252335

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macocci7/php-math-integer",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "PHP Math Library of the subjects of number theory(only natural number).",
55
"type": "library",
66
"license": "MIT",

src/Fraction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public function reduce()
164164
*/
165165
public function toCommonDenominator(Fraction &$f)
166166
{
167+
if (0 === (int) $this->denominator || 0 === (int) $f->denominator) {
168+
throw new \Exception('denominator must not be null nor zero.', 1);
169+
}
167170
$cd = $this->m->leastCommonMultiple(
168171
$this->denominator,
169172
$f->denominator

0 commit comments

Comments
 (0)