/** * */ public function testLCMArray() { $this->assertEquals(2, Utils::lcmArray([1, 2])); $this->assertEquals(-2, Utils::lcmArray([-1, 2])); $this->assertEquals(-2, Utils::lcmArray([1, -2])); $this->assertEquals(2, Utils::lcmArray([-1, -2])); $this->assertEquals(28, Utils::lcmArray([4, 7])); $this->assertEquals(8, Utils::lcmArray([4, 8])); $this->assertEquals(6, Utils::lcmArray([1, 2, 3])); $this->assertEquals(-6, Utils::lcmArray([-1, 2, 3])); $this->assertEquals(-6, Utils::lcmArray([1, -2, 3])); $this->assertEquals(-6, Utils::lcmArray([-1, -2, -3])); $this->assertEquals(28, Utils::lcmArray([4, 7, 4])); $this->assertEquals(24, Utils::lcmArray([4, 8, 3])); }
/** * Simplify this fraction * * @return Fraction */ public function simplify() { $g = Utils::gcd($this->numerator, $this->denominator); return new self($this->numerator / $g, $this->denominator / $g); }