public function testSub() { $math = new Math(); //Success $this->assertEquals(3, $math->sub(8, 5)); //Success $this->assertEquals(3, $math->sub(9, 6)); }
/** * Returns the difference of this number and the given one. * * The result has a scale of `max($this->scale, $that->scale)`. * * @param \Arki\Math\Number|int|float|string $that The number to subtract. Must be convertible to a BigDecimal. * * @return BigDecimal The result. * * @throws \ArithmeticError If the number is not valid, or is not convertible to a BigDecimal. */ public function minus($that) { $that = self::of($that); if ($that->intVal->isZero() && $that->scale <= $this->scale) { return $this; } $this->scaleValues($this, $that, $a, $b); $value = Math::sub($a, $b); $scale = $this->scale > $that->scale ? $this->scale : $that->scale; return new self(BigInteger::of($value), $scale); }