コード例 #1
0
 public function testEquals()
 {
     $this->assertTrue(InfiniteDecimal::getPositiveInfinite()->equals(InfiniteDecimal::getPositiveInfinite()));
     $this->assertTrue(InfiniteDecimal::getNegativeInfinite()->equals(InfiniteDecimal::getNegativeInfinite()));
     $this->assertFalse(InfiniteDecimal::getPositiveInfinite()->equals(InfiniteDecimal::getNegativeInfinite()));
     $this->assertFalse(InfiniteDecimal::getNegativeInfinite()->equals(InfiniteDecimal::getPositiveInfinite()));
 }
コード例 #2
0
 public function testInfiniteInfiniteDiv()
 {
     $pInf = InfiniteDecimal::getPositiveInfinite();
     $nInf = InfiniteDecimal::getNegativeInfinite();
     $catched = false;
     try {
         $pInf->div($pInf);
     } catch (\DomainException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
     $catched = false;
     try {
         $pInf->div($nInf);
     } catch (\DomainException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
     $catched = false;
     try {
         $nInf->div($pInf);
     } catch (\DomainException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
     $catched = false;
     try {
         $nInf->div($nInf);
     } catch (\DomainException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
 }
コード例 #3
0
 public function testAsInteger()
 {
     $catched = false;
     try {
         InfiniteDecimal::getPositiveInfinite()->asInteger();
     } catch (InvalidCastException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
     $catched = false;
     try {
         InfiniteDecimal::getNegativeInfinite()->asInteger();
     } catch (InvalidCastException $e) {
         $catched = true;
     }
     $this->assertTrue($catched);
 }
コード例 #4
0
 /**
  * Internal method used to compute arctan and arccotan
  *
  * @param Decimal $x
  * @param Decimal $firstTerm
  * @param $scale
  * @return Decimal
  */
 private static function simplePowerSerie(Decimal $x, Decimal $firstTerm, $scale)
 {
     $approx = $firstTerm;
     $change = InfiniteDecimal::getPositiveInfinite();
     $xPowerN = DecimalConstants::One();
     // Calculates x^n
     $sign = DecimalConstants::One();
     // Calculates a_n
     for ($i = 1; !$change->floor($scale + 2)->isZero(); $i++) {
         $xPowerN = $xPowerN->mul($x);
         if ($i % 2 === 0) {
             $factorN = DecimalConstants::zero();
         } else {
             if ($i % 4 === 1) {
                 $factorN = DecimalConstants::one()->div(Decimal::fromInteger($i), $scale + 2);
             } else {
                 $factorN = DecimalConstants::negativeOne()->div(Decimal::fromInteger($i), $scale + 2);
             }
         }
         if (!$factorN->isZero()) {
             $change = $factorN->mul($xPowerN, $scale + 2);
             $approx = $approx->add($change, $scale + 2);
         }
     }
     return $approx->round($scale);
 }
コード例 #5
0
 public function testPInfiniteLog10()
 {
     $pInf = InfiniteDecimal::getPositiveInfinite();
     $this->assertTrue($pInf->log10()->equals($pInf));
 }
コード例 #6
0
 public function testNegativeInfinite()
 {
     $this->assertTrue(InfiniteDecimal::getNegativeInfinite()->exp()->isZero());
 }
コード例 #7
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Cosecant function hasn't limit in the negative infinite.
  */
 public function testFiniteNegativeInfiniteCosec()
 {
     InfiniteDecimal::getNegativeInfinite()->cosec();
 }
コード例 #8
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Infinite elevated to zero is undefined.
  */
 public function testNegativeInfiniteZeroPower()
 {
     InfiniteDecimal::getNegativeInfinite()->pow(DecimalConstants::Zero());
 }
コード例 #9
0
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Sine function hasn't limit in the negative infinite.
  */
 public function testFiniteNegativeInfiniteSin()
 {
     InfiniteDecimal::getNegativeInfinite()->sin();
 }