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
- 
Calculate modulus with positive divisor: julia> mod(10, 3) 1The modfunction returns the remainder when10is divided by3. In this case, the result is1.
- 
Modulus with negative divisor: julia> mod(10, -3) -2When the divisor is negative, the modfunction returns a value within the range (y,0]. In this case, the result is-2.
- 
Modulus with floating-point numbers: julia> mod(10.5, 3) 1.5The modfunction works with floating-point numbers as well. It returns the remainder when10.5is divided by3, which is1.5.
- Modulus with negative dividend and divisor:
julia> mod(-10, -3) -1When both the dividend and divisor are negative, the modfunction 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 errorIn 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.
