pi() public static method

Returns the Pi number.
public static pi ( ) : Decimal
return Decimal
 public function testFiniteAbs()
 {
     $this->assertTrue(DecimalConstants::pi()->equals(Decimal::fromString("3.14159265358979323846264338327950")));
     $this->assertTrue(DecimalConstants::eulerMascheroni()->equals(Decimal::fromString("0.57721566490153286060651209008240")));
     $this->assertTrue(DecimalConstants::goldenRatio()->equals(Decimal::fromString("1.61803398874989484820458683436564")));
     $this->assertTrue(DecimalConstants::lightSpeed()->equals(Decimal::fromInteger(299792458)));
 }
示例#2
0
 /**
  * Calculates the arccotangente of this with the highest possible accuracy
  *
  * @param integer $scale
  * @return Decimal
  */
 public function arccot($scale = null)
 {
     $scale = $scale === null ? 32 : $scale;
     $piOverTwo = DecimalConstants::pi()->div(Decimal::fromInteger(2), $scale + 2);
     if ($this->round($scale)->isZero()) {
         return $piOverTwo->round($scale);
     }
     $piOverFour = DecimalConstants::pi()->div(Decimal::fromInteger(4), $scale + 2);
     if ($this->round($scale)->equals(DecimalConstants::one())) {
         return $piOverFour->round($scale);
     }
     if ($this->round($scale)->equals(DecimalConstants::negativeOne())) {
         return DecimalConstants::negativeOne()->mul($piOverFour, $scale + 2)->round($scale);
     }
     return $piOverTwo->sub(self::simplePowerSerie($this, DecimalConstants::zero(), $scale + 2))->round($scale);
 }
示例#3
0
 /**
  * Calculates the arccosecant of this with the highest possible accuracy
  *
  * @param integer $scale
  * @return Decimal
  */
 public function arccsc($scale = null)
 {
     if ($this->comp(DecimalConstants::one(), $scale + 2) === -1 && $this->comp(DecimalConstants::negativeOne(), $scale + 2) === 1) {
         throw new \DomainException("The arccosecant of this number is undefined.");
     }
     $scale = $scale === null ? 32 : $scale;
     if ($this->round($scale)->equals(DecimalConstants::one())) {
         return DecimalConstants::pi()->div(Decimal::fromInteger(2), $scale + 2)->round($scale);
     }
     if ($this->round($scale)->equals(DecimalConstants::negativeOne())) {
         return DecimalConstants::pi()->div(Decimal::fromInteger(-2), $scale + 2)->round($scale);
     }
     return self::powerSerie(DecimalConstants::one()->div($this, $scale + 2), DecimalConstants::zero(), $scale + 2)->round($scale);
 }