Integer type multiplication

@param  NI $a first operand
@param  NI $b second operand

@return IntType
516731
public function intMul(NI $a, NI $b)
    {
        list($a, $b) = $this->checkIntTypes($a, $b);

        return new IntType($a() * $b());
    }
878201
public static function floorMod(int $a, int $b) : int
    {
        return (($a % $b) + $b) % $b;
    }
1191126
function bnpFromNumber(a, b) {
    if ("number" == typeof b) {
        // new BigInteger(int,int,RNG)
        if (a < 2) this.fromInt(1);
        else {
            this.fromNumber(a);
            if (!this.testBit(a - 1))	// force MSB set
                this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
            if (this.isEven()) this.dAddOffset(1, 0); // force odd
            while (!this.isProbablePrime(b)) {
                this.dAddOffset(2, 0);
                if (this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
            }
        }
    } else {
        // new BigInteger(int,RNG)
        var x = crypt.randomBytes((a >> 3) + 1)
        var t = a & 7;

        if (t > 0)
            x[0] &= ((1 << t) - 1);
        else
            x[0] = 0;

        this.fromByteArray(x);
    }
}
666859
public function computeWithoutBcMath(DecimalNumber $a, DecimalNumber $b)
    {
        $aAsString = (string) $a;
        $bAsString = (string) $b;

        // optimization: if either one is zero, the result is zero
        if ('0' === $aAsString || '0' === $bAsString) {
            return new DecimalNumber('0');
        }

        // optimization: if either one is one, the result is the other one
        if ('1' === $aAsString) {
            return $b;
        }
        if ('1' === $bAsString) {
            return $a;
        }

        $result = $this->multiplyStrings(
            ltrim($a->getCoefficient(), '0'),
            ltrim($b->getCoefficient(), '0')
        );

        $sign = ($a->isNegative() xor $b->isNegative()) ? '-' : '';

        // a multiplication has at most as many decimal figures as the sum
        // of the number of decimal figures the factors have
        $exponent = $a->getExponent() + $b->getExponent();

        return new DecimalNumber($sign . $result, $exponent);
    }
987814
public static function gcd($a, $b) {
        return ($b == 0) ? ($a):(self::gcd($b, $a % $b));
    }
1061171
private int modularExponentation(int a, int b, int n) throws IllegalArgumentException {
        int result = 1;
        int counter;
        int maxBinarySize = 32;
        boolean[] b2Binary = new boolean[maxBinarySize];
        for (counter = 0; b > 0; counter++) {
            if (counter >= maxBinarySize){
                throw new IllegalArgumentException("Exponent "+b+" is too big !");
            }
            b2Binary[counter] = (b % 2 != 0);
            b = b / 2;
        }
        for (int k = counter - 1; k >= 0; k--) {
            result = (result * result) % n;
            if (b2Binary[k]){
                result = (result * a) % n;
            }
        }
        return result;
    }
38201
function mult($a, $b)
    {
        $sum = $this->ltable[$a] + $this->ltable[$b];
        $sum %= 255;
        // Get the antilog
        $sum = $this->atable[$sum];

        return ($a == 0 ? 0 : ($b == 0 ? 0 : $sum));
    }
1139149
@Override
    public double compute(double a, double b) {
        return (a * b) / (2 - (a + b - a * b));
    }
55930
private function getTypePairing(NumericTypeInterface $a, NumericTypeInterface $b)
    {
        $search = [
            'Chippyash\Type\Number\Rational\\',
            'Chippyash\Type\Number\Complex\\',
            'Chippyash\Type\Number\\',
            'Type'
        ];
        $replace = ['', '', '', ''];
        $tA = strtolower(str_replace($search, $replace, get_class($a)));
        $tB = strtolower(str_replace($search, $replace, get_class($b)));

        return "{$tA}:{$tB}";
    }
1035729
public function compareUsingBcMath(DecimalNumber $a, DecimalNumber $b)
    {
        return bccomp((string) $a, (string) $b, max($a->getExponent(), $b->getExponent()));
    }
872557
public function floatDiv(NI $a, NI $b)
    {
        list($a, $b) = $this->checkFloatTypes($a, $b);
        return new FloatType($a() / $b());
    }
497414
public function naturalAdd(NI $a, NI $b)
    {
        list($a, $b) = $this->checkIntTypes($a, $b);
        return new NaturalIntType($a() + $b());
    }
405075
public static function Multiply( $a, $b )
	{
		if ( ! is_numeric( $b ) )
			throw new \InvalidArgumentException( "Division denominator is not a number" );

		if ( is_nan( $b ) )
	        throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );

        if ( $b == INF || $b == -INF )
        	throw XPath2Exception::withErrorCode( "FODT0002", Resources::FODT0002 );

		if ( ! $a instanceof DayTimeDurationValue )
	        throw new ArgumentException("$a");

		// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.
		$multipliedSeconds = $a->getTotalSeconds()->Mul( $b )->getRound(3);
		$multipliedInterval = new \DateInterval("P0D");
		$multipliedInterval->s = $multipliedSeconds->getIntegerPart();
		$microseconds = $multipliedSeconds->getDecimalPart() + 0;
		$sign = $multipliedSeconds->getIsNegative();

		// Finally convert $multipliedInterval into a normalized interval
		$dt = new \DateTimeImmutable();
		$tz = new \DateTimeZone("Z");
		$dt = $dt->setTimezone( $tz );
		$diff = $dt->add( $multipliedInterval )->diff( $dt );
		$diff->hasValue = $multipliedSeconds->getValue() != 0;
		$diff->invert = ! $diff->invert;
		$diff->microseconds = $microseconds;
		// $diff->daysOnly = false;

	    return new DayTimeDurationValue( $diff );
	}
1002492
public static double mod(double a, double b) {
		int n = (int)(a/b);
		
		a -= n*b;
		if (a < 0)
			return a + b;
		return a;
	}
717276
public function computeWithoutBcMath(DecimalNumber $a, DecimalNumber $b)
    {
        if ($a->isNegative()) {
            if ($b->isNegative()) {
                // if both numbers are negative,
                // we can just add them as positive numbers and then invert the sign
                // f(x, y) = -(|x| + |y|)
                // eg. f(-1, -2) = -(|-1| + |-2|) = -3
                // eg. f(-2, -1) = -(|-2| + |-1|) = -3
                return $this
                    ->computeWithoutBcMath($a->toPositive(), $b->toPositive())
                    ->invert();
            }
            // if the number is negative and the addend positive,
            // perform an inverse subtraction by inverting the terms
            // f(x, y) = y - |x|
            // eg. f(-2, 1) = 1 - |-2| = -1
            // eg. f(-1, 2) = 2 - |-1| = 1
            // eg. f(-1, 1) = 1 - |-1| = 0
            return $b->minus(
                $a->toPositive()
            );
        }

        if ($b->isNegative()) {
            // if the number is positive and the addend is negative
            // perform subtraction instead: 2 - 1
            // f(x, y) = x - |y|
            // f(2, -1) = 2 - |-1| = 1
            // f(1, -2) = 1 - |-2| = -1
            // f(1, -1) = 1 - |-1| = 0
            return $a->minus(
                $b->toPositive()
            );
        }

        // optimization: 0 + x = x
        if ('0' === (string) $a) {
            return $b;
        }

        // optimization: x + 0 = x
        if ('0' === (string) $b) {
            return $a;
        }

        // pad coefficients with leading/trailing zeroes
        list($coeff1, $coeff2) = $this->normalizeCoefficients($a, $b);

        // compute the coefficient sum
        $sum = $this->addStrings($coeff1, $coeff2);

        // both signs are equal, so we can use either
        $sign = $a->getSign();

        // keep the bigger exponent
        $exponent = max($a->getExponent(), $b->getExponent());

        return new DecimalNumber($sign . $sum, $exponent);
    }
1127444
public static function divide($a, $b)
    {
        if (function_exists('gmp_div_q')) {
            return gmp_div_q($a, $b);
        }

        return bcdiv($a, $b, 0);
    }
828637
public function floatAdd(NI $a, NI $b)
    {
        list($a, $b) = $this->checkFloatTypes($a, $b);
        return new FloatType($a() + $b());
    }