コード例 #1
0
ファイル: UtilsTest.php プロジェクト: tazorax/math-utils
 /**
  *
  */
 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]));
 }
コード例 #2
0
ファイル: Fraction.php プロジェクト: tazorax/math-utils
 /**
  * Simplify this fraction
  *
  * @return Fraction
  */
 public function simplify()
 {
     $g = Utils::gcd($this->numerator, $this->denominator);
     return new self($this->numerator / $g, $this->denominator / $g);
 }