Calculates the modulus of this money.

@param mixed $modulus the modulus to apply

@return Money

@throws \InvalidArgumentException if the $modulus is not numeric
421639
public function modulus($modulus)
    {
        if (!is_numeric($modulus)) {
            throw new \InvalidArgumentException('Modulus must be numeric');
        }

        $amount = bcmod($this->amount, strval($modulus));

        return self::valueOf($amount, $this->currency);
    }
611640
public function allocateToTargets($n)
    {
        if (is_int($n)) {
            $n = (float)$n;
        }

        if (!is_float($n)) {
            throw new InvalidArgumentException('$n ' . \Yii::t('skeeks/money', 'must be an integer'));
        }

        $low = $this->newMoney(floatval($this->amount / $n));
        $high = $this->newMoney($low->getAmount() + 1);
        $remainder = $this->amount % $n;
        $result = array();

        for ($i = 0; $i < $remainder; $i++) {
            $result[] = $high;
        }

        for ($i = $remainder; $i < $n; $i++) {
            $result[] = $low;
        }

        return $result;
    }
379735
public static function fromDecimal(Decimal $decValue, int $scale = null): Decimal
    {
        self::paramsValidation($decValue, $scale);

        // This block protect us from unnecessary additional instances
        if ($scale === null || $scale >= $decValue->scale) {
            return $decValue;
        }

        return new static(
            self::innerRound($decValue->value, $scale),
            $scale
        );
    }
334840
public function mod($b)
    {
        switch (true) {
            case $b instanceof Vector:
                $c = $this->modVector($b);
                break;

            case $b instanceof Matrix:
                $c = $this->modMatrix($b);
                break;

            case is_int($b) or is_float($b):
                $c = $this->modScalar($b);
                break;

            default:
                throw new InvalidArgumentException('Cannot mod vector'
                    . ' with a ' . gettype($b) . '.');
        }

        return $c;
    }
172205
public function multiply(float $factor, int $roundingMode) : Money
    {
        if (!in_array($roundingMode, self::$roundingModes, true)) {
            throw InvalidArgumentException::format(
                'Invalid rounding mode supplied to %s: expecting one of (%s), %s given',
                __METHOD__, Debug::formatValues(self::$roundingModes), $roundingMode
            );
        }

        return new Money((int)round($this->amount * $factor, 0, $roundingMode), $this->currency);
    }
986603
public static function roundMoneyValue($moneyValue, $targetDigits, $havingDigits)
    {
        $valueLength = strlen($moneyValue);
        $shouldRound = $targetDigits < $havingDigits && $valueLength - $havingDigits + $targetDigits > 0;

        if ($shouldRound && $moneyValue[$valueLength - $havingDigits + $targetDigits] >= 5) {
            $position = $valueLength - $havingDigits + $targetDigits;
            $addend = 1;

            while ($position > 0) {
                $newValue = (string) ((int) $moneyValue[$position - 1] + $addend);

                if ($newValue >= 10) {
                    $moneyValue[$position - 1] = $newValue[1];
                    $addend = $newValue[0];
                    --$position;
                    if ($position === 0) {
                        $moneyValue = $addend.$moneyValue;
                    }
                } else {
                    if ($moneyValue[$position - 1] === '-') {
                        $moneyValue[$position - 1] = $newValue[0];
                        $moneyValue = '-'.$moneyValue;
                    } else {
                        $moneyValue[$position - 1] = $newValue[0];
                    }

                    break;
                }
            }
        }

        return $moneyValue;
    }
1145045
public function Mod( $denominator )
	{
		$denominator = $denominator instanceof DecimalValue ? $denominator : Convert::ToDecimal( $denominator );

		if ( $denominator->getIsZero() )
			throw XPath2Exception::withErrorCode( "FOAR0001", Resources::FOAR0001 );

		if ( $denominator->getIsNAN() )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		if ( $this->getIsNAN() || $this->getIsInfinite() )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		$power = 0;
		// bcmod does not handle decimals so if they exist the powers of the two numbers must be increased until there are no decimals
		if ( $this->getIsDecimal() )
		{
			$power = strlen( $this->getIntegerPart() );
		}

		if ( $denominator->getIsDecimal() )
		{
			$power = max( strlen( $denominator->getIntegerPart() ), $power );
		}

		$multiplier = new DecimalValue( 10 );
		$multiplier = $multiplier->Pow( new DecimalValue( $power ) );
		$numerator = $this->Mul( $multiplier );
		$denominator = $denominator->Mul( $multiplier );
		$mod = bcmod( $numerator->getIntegerPart(), $denominator->getIntegerPart() );

		// Now need to divide by the multiplier to restore the correct power
		$mod = new DecimalValue( $mod );
		$mod = $mod->Div( $multiplier );
		return $mod;
	}
843860
public static function calculate( $integer )
	{
		Deprecation::getInstance()
			->setErrorVersion( '0.8.5' )
			->setExceptionVersion( '0.9' )
			->message( sprintf(
				'Please use %s (%s) instead',
				'public library "CeusMedia/Math"',
			 	'https://packagist.org/packages/ceus-media/math'
			) );
		if( $integer < 0 )
			throw new InvalidArgumentException( "Factorial is defined for positive natural Numbers only" );
		else if( !is_int( $integer ) )
			throw new InvalidArgumentException( "Factorial is defined for natural Numbers (Integer) only" );
		else if( $integer == 0 )
			return 1;
		else
			return $integer * self::calculate( $integer - 1 );
		return 0;
	}
93102
public static function sqrt($base)
    {
        if (!static::is($base)) {
            throw new \InvalidArgumentException(
                "The \$base parameters must be of type int (or string representing a big int)."
            );
        }

        if (is_int($base)) {
            return sqrt($base);
        } elseif (function_exists('bcsqrt')) {
            return bcsqrt($base);
        }

        throw new \RuntimeException("The BCMath library is not available."); // @codeCoverageIgnore
    }
219566
public function getAmount($amount)
    {
        if (!is_float($amount) &&
            $this->getCurrencyDecimalPlaces() > 0 &&
            false === strpos((string) $amount, '.')) {
            throw new InvalidArgumentException(
                'Please specify amount as a string or float, '.
                'with decimal places (e.g. \'10.00\' to represent $10.00).'
            );
        }

        return $this->formatCurrency($amount);
    }
283582
public function numeric()
    {
        if (!is_int($this->value) && !is_float($this->value) && !is_string($this->value)) {
            throw new InvalidIntOrFloatOrStringException($this->name, $this->value);
        } elseif (!is_numeric($this->value)) {
            throw new InvalidNumericException($this->name, $this->value);
        }

        return $this;
    }
1151945
public function setAmount($amount)
    {
        if ($amount === null) {
            $this->amount = 0;
            return $this;
        }
        
        if (!is_int($amount)) {
            throw new InvalidArgumentException(sprintf(
                'Amount must be an integer, "%s" given',
                is_object($amount) ? get_class($amount) : gettype($amount)
            ));
        }
        
        // Overflow check is not necessary because we have an integer
        $this->amount = $amount;
        return $this;
    }
1018796
public function interpolate( $tolerance )
	{
		$a	= $this->interval->getStart();
		$b	= $this->interval->getEnd();
		$c	= false;
		do{
			$ya	= $this->formula->getValue( $a );
			$yb	= $this->formula->getValue( $b );

			if( $ya * $yb > 0 )
			{
				throw new InvalidArgumentException( 'Formula has no 0 in Interval '.(string)$this->interval.'.' );
				break;
			}
			$c	= ( $a * $yb - $b * $ya ) / ( $yb - $ya );
			$found = $c - $a <= $tolerance || $b - $c <= $tolerance;
			if( $c >= 0 && $a >= 0 || $c < 0 && $a < 0 )
				$a	= $c;
			else
				$b	= $c;
		}
		while( !$found );
		return $c;
	}
398746
public function setPrecision($precision)
	{
		$available = [self::PRECISION_FIXED, self::PRECISION_DOUBLE, self::PRECISION_FLOAT];
		
		if ( ! is_scalar($precision) || ! in_array($precision, $available, false))
		{
			throw new \InvalidArgumentException(sprintf('Wrong precision value for %s, available values are %s',
				(string) $precision, implode(', ', $available)));
		}
		
		$this->precision = (string) $precision;
		
		return $this;
	}
1030221
public function setAmount($value)
    {
        if ($value === null || $value === '') {
            $this->amount = new MonetaryAmount();
        } elseif (is_object($value) && $value instanceof AmountInterface) {
            $this->amount->setValue($value->getValue());
            $this->amount->setCurrency($value->getCurrency());
        } elseif (is_array($value)) {
            $this->amount->fromArray($value);
        } else {
            $this->amount->setValue($value);
        }

        return $this;
    }
892412
public function divide($divisor, $roundingMode = self::ROUND_HALF_UP)
    {
        $this->assertOperand($divisor);
        $this->assertRoundingMode($roundingMode);

        $divisor = (string) Number::fromNumber($divisor);

        if ($this->getCalculator()->compare($divisor, '0') === 0) {
            throw new \InvalidArgumentException('Division by zero');
        }

        $quotient = $this->round($this->getCalculator()->divide($this->amount, $divisor), $roundingMode);

        return $this->newInstance($quotient);
    }
1201016
public function fromFloat($amount, $currency = null)
    {
        if ($currency) {
            $this->setCurrency($currency);
        }

        if (!is_float($amount)) {
            throw new InvalidArgumentException(sprintf(
                'Amount must be a float, %s given',
                gettype($amount)
            ));
        }
        
        $this->amount = $this->toInt(
            round(
                $this->getSubUnit() * round($amount, $this->getFractionDigits(), PHP_ROUND_HALF_UP),
                0,
                PHP_ROUND_HALF_UP
            )
        );
        return $this;
    }