julia_Julia的分区错误

julia

div() function is used to divide for the integer division, by using this function we can get exception/error at two cases,

div()函数用于除以整数除法,通过使用此函数,我们可以在两种情况下获得异常/错误,

  1. Dividing an integer by zero (Consider example 1)

    将整数除以零( 请考虑示例1 )

  2. 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


翻译自: https://www.includehelp.com/julia/division-errors.aspx

julia

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值