public function testGetWithNoCalculatorSetDetectsCalculator() { $currentCalculator = Calculator::get(); Calculator::set(null); $this->assertInstanceOf(Calculator::getNamespace(), Calculator::get()); Calculator::set($currentCalculator); }
/** * Returns a string representation of this number in the given base. * * @param int $base * * @return string * * @throws \InvalidArgumentException If the base is out of range. */ public function toBase($base) { $base = (int) $base; if ($base === 10) { return $this->value; } if ($base < 2 || $base > 36) { throw new \InvalidArgumentException(sprintf('Base %d is out of range [2, 36]', $base)); } $dictionary = '0123456789abcdefghijklmnopqrstuvwxyz'; $calc = Calculator::get(); $value = $this->value; $negative = $value[0] === '-'; if ($negative) { $value = substr($value, 1); } $base = (string) $base; $result = ''; while ($value !== '0') { list($value, $remainder) = $calc->divQR($value, $base); $remainder = (int) $remainder; $result .= $dictionary[$remainder]; } if ($negative) { $result .= '-'; } return strrev($result); }
/** * {@inheritdoc} */ public function compareTo($that) { $that = BigNumber::of($that); if ($that instanceof BigInteger) { $that = $that->toBigDecimal(); } if ($that instanceof BigDecimal) { $this->scaleValues($this, $that, $a, $b); return Calculator::get()->cmp($a, $b); } return -$that->compareTo($this); }