Creates instance that adds the given monetary value

@param Money $other The other monetary value

@return Money

@throws DomainException When other has different currency
@throws RangeException When integer overflow occurs
765786
public function add(Money $other): Money
    {
        $this->guardCurrency($other);

        $amount = $this->amount + $other->amount;

        $this->guardAmountInBounds($amount);

        return $this->withAmount($amount);
    }
390562
private static Currency createCurrency(
      String commonCode, String name, String unicode, String... alternativeCodes) {

    CurrencyAttributes attributes =
        new CurrencyAttributes(commonCode, name, unicode, alternativeCodes);

    Currency currency = new Currency(commonCode, attributes);

    for (String code : attributes.codes) {
      if (commonCode.equals(code)) {
        // common code will always be part of the currencies map

        currencies.put(code, currency);

      } else if (!currencies.containsKey(code)) {
        // alternative codes will never overwrite common codes

        currencies.put(code, new Currency(code, attributes));
      }
    }

    return currency;
  }
585422
public function setFee(Money $money): ShippingMethodInterface
    {
        $this->feeAmount = $money->getAmount();
        $this->feeCurrency = $money->getCurrency()->getCode();

        return $this;
    }
638280
public function add(Bigint $other): Bigint
    {
        $result = clone $this;
        $overflow = false;
        for ($i = 0; $i < 8; $i++) {
            $result->bytes[$i] += $other->bytes[$i];
            if ($overflow) {
                $result->bytes[$i]++;
                $overflow = false;
            }
            if ($result->bytes[$i] & 0x100) {
                $overflow = true;
                $result->bytes[$i] &= 0xFF;
            }
        }
        if ($overflow) {
            throw new OverflowException;
        }
        return $result;
    }
76421
public function integer($values, string $currency = null): int
    {
        [$className, $value] = $this->classAndValue($values, $currency, false);

        return (new $className)->integer($value);
    }
1179969
public function setCurrency($currency)
    {
        if ($currency) {
            $currency = strtoupper($currency);
            Currency::getNumericCode($currency); // ensure currency support
            $this->currency = $currency;
        } else {
            $this->currency = null;
        }

        return $this;
    }
260563
public function compare(Money $other)
    {
        $this->assertSameCurrency($other);

        return bccomp($this->amount, $other->getAmountString(), self::GAAP_PRECISION);
    }
250320
public function mod(Money $divisor)
    {
        $this->assertSameCurrency($divisor);

        return new self($this->getCalculator()->mod($this->amount, $divisor->amount), $this->currency);
    }
999149
protected function updateCurrency(Money $money): self
    {
        if ($this->currency && $money->getCurrency()->getCode() !== $this->currency) {
            throw new CurrencyMismatchException('The currency on this stock movement is not the same as the one your Money object');
        }

        $this->currency = $money->getCurrency()->getCode();

        return $this;
    }
508101
public function add(Money $money) : Money
    {
        $this->verifySameCurrency(__METHOD__, $money);

        return new Money($this->amount + $money->amount, $this->currency);
    }
517226
private function newWrappedMoneyFromMoney(MoneyInterface $money)
    {
        return new WrappedMoney(
            $money->getAmount(),
            new WrappedCurrency(
                $money
                    ->getCurrency()
                    ->getIso()
            )
        );
    }
576868
public function compare(self $other)
    {
        $this->assertSameCurrency($other);

        if ($this->amount < $other->amount) {
            return -1;
        }

        if ($this->amount > $other->amount) {
            return 1;
        }

        return 0;
    }
1214750
public function subtract(Money $money)
    {
        $this->assertSameCurrency($money);
        $amount = $this->amount->sub($money->amount, $this->getInnerPrecision());

        return $this->newInstance($amount);
    }
375044
public function equals(Money $other)
    {
        return $this->isSameCurrency($other) && $this->amount === $other->amount;
    }
795191
public function subtract(Money $money) : Money
    {
        $this->verifySameCurrency(__METHOD__, $money);

        return $this->add($money->negate());
    }
1228256
public function subtract(Money $money)
    {
        if (!$this->currency->equals($money->getCurrency())) {
            throw new CurrencyMismatchException($this.' does not match '.$money);
        }

        $amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);

        return self::valueOf($amount, $this->currency);
    }
725659
@Override
    public Money add(MonetaryAmount amount) {
        MoneyUtils.checkAmountParameter(amount, this.currency);
        if (amount.isZero()) {
            return this;
        }
        return new Money(this.number.add(amount.getNumber().numberValue(BigDecimal.class)), getCurrency());
    }