Esempio n. 1
0
 public function testHelperConstructorMethods()
 {
     $first = Rational::makeInteger($this->makeInteger(15));
     $this->assertRational($first);
     $this->assertEquals($first->getNumerator()->getValue(), 15);
     $this->assertEquals($first->getDenominator()->getValue(), 1);
     $second = Rational::makeZero($this->makeInteger(5));
     $this->assertRational($second);
     $this->assertEquals($second->getNumerator()->getValue(), 0);
     $this->assertEquals($second->getDenominator()->getValue(), 5);
     $third = Rational::makeZero();
     $this->assertRational($third);
     $this->assertEquals($third->getNumerator()->getValue(), 0);
     $this->assertNotEquals($third->getDenominator()->getValue(), 0);
 }
Esempio n. 2
0
 /**
  * @param Rational $value
  * @return bool
  */
 public function isLessThan(Rational $value) : bool
 {
     $first = $this->getSimplified();
     $second = $value->getSimplified();
     $lcm = $first->getDenominator()->getLcm($second->getDenominator())->getValue();
     $left = $first->getNumerator()->getValue();
     $left *= $lcm / $first->getDenominator()->getValue();
     $right = $second->getNumerator()->getValue();
     $right *= $lcm / $second->getDenominator()->getValue();
     return $left < $right;
 }