julia
div() function is used to divide for the integer division, by using this function we can get exception/error at two cases,
div()函数用于除以整数除法,通过使用此函数,我们可以在两种情况下获得异常/错误,
Dividing an integer by zero (Consider example 1)
将整数除以零( 请考虑示例1 )
Dividing the lowest negative number integer by -1 (Consider example 2)
将最低负数整数除以-1( 请考虑示例2 )
In the above two cases, a DivideError throws.
在上述两种情况下,将引发DivideError 。
There is another exceptional case with the rem() and mod() functions when the second argument is zero (Consider example 3).
当第二个参数为零时, rem()和mod()函数还有另一种例外情况( 请考虑示例3 )。
Example 1:
范例1:
# Case 1: Dividing an integer by zero
x = 10
y = 2
println("x: ", x)
println("y: ", y)
result = div(x,y)
println("result: ", result)
# assigning 0 to y
y = 0
result = div(x,y)
println("result: ", result)
Output
输出量
x: 10
y: 2
result: 5
ERROR: LoadError: DivideError: integer division error
Example 2:
范例2:
# Case 2: Dividing the lowest negative number integer by -1
x = 10
y = 2
println("x: ", x)
println("y: ", y)
result = div(x,y)
println("result: ", result)
# assigning lowest negative number integer to x
# and -1 to y
x = typemin(Int64)
y = -1
result = div(x,y)
println("result: ", result)
Output
输出量
x: 10
y: 2
result: 5
ERROR: LoadError: DivideError: integer division error
Example 3:
范例3:
# Case 3: With the rem() and mod() functions
# when the second argument is zero
x = 10
y = 3
println("x: ", x)
println("y: ", y)
println("rem(x,y): ", rem(x,y))
println("mod(x,y): ", mod(x,y))
# assigning 0 to y
y = 0
println("rem(x,y): ", rem(x,y))
println("mod(x,y): ", mod(x,y))
Output
输出量
x: 10
y: 3
rem(x,y): 1
mod(x,y): 1
ERROR: LoadError: DivideError: integer division error
julia