div
div(x, y) ÷(x, y)
The quotient from Euclidean division. Computes x/y
, truncated to an integer.
Examples
-
Perform Euclidean division:
julia> div(10, 3) 3
This example performs Euclidean division of 10 by 3, resulting in the quotient 3.
-
Handle negative numbers:
julia> div(-10, 3) -3
The
div
function can handle negative numbers as well. In this example, it computes the quotient of -10 divided by 3, resulting in -3. - Truncate decimal values:
julia> div(17, 5) 3
The
div
function truncates the decimal part of the division result. Here, 17 divided by 5 is 3.4, but the decimal part is discarded, resulting in the quotient 3.
Common mistake example:
julia> div(10, 0)
ERROR: DivideError: integer division error
In this example, division by zero is attempted, which is not allowed. It's important to ensure that the divisor (y
) is not zero to avoid such errors. Always make sure the divisor is a non-zero value when using the div
function.
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.