/** * Checks if the value represented by this object is negative * * @return bool */ public function isNegative() { return $this->amount->isNegative(); }
/** * Counts the number of significative digits of $val. * Assumes a consistent internal state (without zeros at the end or the start). * * @param Decimal $val * @param Decimal $abs $val->abs() * @return integer */ private static function countSignificativeDigits(Decimal $val, Decimal $abs) { return strlen($val->value) - ($abs->comp(DecimalConstants::One()) === -1 ? 2 : max($val->scale, 1)) - ($val->isNegative() ? 1 : 0); }
/** * Powers this value to $b * * @param Decimal $b exponent * @param integer $scale * @return Decimal */ public function pow(Decimal $b, $scale = null) { if ($b->isPositive()) { if ($this->isPositive()) { return $this; } // if ($this->isNegative()) if ($b->isInfinite()) { throw new \DomainException("Negative infinite elevated to infinite is undefined."); } if ($b->isInteger()) { if (preg_match('/^[+\\-]?[0-9]*[02468](\\.0+)?$/', $b->value, $captures) === 1) { // $b is an even number return self::$pInf; } else { // $b is an odd number return $this; // Negative Infinite } } throw new NotImplementedException("See issues #21, #22, #23 and #24 on Github."); } else { if ($b->isNegative()) { return DecimalConstants::Zero(); } else { if ($b->isZero()) { throw new \DomainException("Infinite elevated to zero is undefined."); } } } }