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()));
 }
 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);
 }
 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);
 }
 /**
  * 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);
 }
 public function testPInfiniteLog10()
 {
     $pInf = InfiniteDecimal::getPositiveInfinite();
     $this->assertTrue($pInf->log10()->equals($pInf));
 }
 public function testNegativeInfinite()
 {
     $this->assertTrue(InfiniteDecimal::getNegativeInfinite()->exp()->isZero());
 }
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Cosecant function hasn't limit in the negative infinite.
  */
 public function testFiniteNegativeInfiniteCosec()
 {
     InfiniteDecimal::getNegativeInfinite()->cosec();
 }
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Infinite elevated to zero is undefined.
  */
 public function testNegativeInfiniteZeroPower()
 {
     InfiniteDecimal::getNegativeInfinite()->pow(DecimalConstants::Zero());
 }
 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Sine function hasn't limit in the negative infinite.
  */
 public function testFiniteNegativeInfiniteSin()
 {
     InfiniteDecimal::getNegativeInfinite()->sin();
 }