/** * 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); }
public function testNegativeWithPositiveExponent() { $nFive = Decimal::fromInteger(-5); $this->assertTrue($nFive->pow(DecimalConstants::One())->equals($nFive)); $this->assertTrue($nFive->pow(Decimal::fromInteger(2))->equals(Decimal::fromInteger(25))); $this->assertTrue($nFive->pow(Decimal::fromInteger(3))->equals(Decimal::fromInteger(-125))); }