mod

mod(x, y)

Modulus after division, returning in the range [0,y), if y is positive, or (y,0] if y is negative.

Examples

  1. Calculate modulus with positive divisor:

    julia> mod(10, 3)
    1

    The mod function returns the remainder when 10 is divided by 3. In this case, the result is 1.

  2. Modulus with negative divisor:

    julia> mod(10, -3)
    -2

    When the divisor is negative, the mod function returns a value within the range (y, 0]. In this case, the result is -2.

  3. Modulus with floating-point numbers:

    julia> mod(10.5, 3)
    1.5

    The mod function works with floating-point numbers as well. It returns the remainder when 10.5 is divided by 3, which is 1.5.

  4. Modulus with negative dividend and divisor:
    julia> mod(-10, -3)
    -1

    When both the dividend and divisor are negative, the mod function returns a value within the range [0, y). In this case, the result is -1.

Common mistake example:

julia> mod(10, 0)
ERROR: DivideError: integer division error

In this example, an error occurs because the divisor is 0. The mod function cannot perform division by zero, so it's important to avoid this mistake and ensure the divisor is non-zero.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: