public function testDivisionByZero() { $x = Rational::parse('1/2'); $y = Rational::parse('0'); $this->setExpectedException(DivisionByZeroException::class); $z = Rational::div($x, $y); }
/** * convert data to a floating point number, if possible * * * @param mixed $value (float, int, Rational) * @throws SyntaxErrorException if the string cannot be parsed * @retval float */ private static function toFloat($x) { if (is_float($x)) { return $x; } if (is_int($x)) { return $x; } if (is_string($x)) { $r = Rational::parse($x); return $r->p / $r->q; } throw new SyntaxErrorException(); }