Wednesday, 16 March 2016

Julia: DivideError

DivideError thrown, when you perform integer division with denominator 0 by using the functions div(), rem(), mod().


Method
Description
div(x, y)
Computes x/y. Result is truncated to an integer.

julia> div(10, 3)
3

julia> div(10, 3.0)
3.0

julia> div(10.0, 3.0)
3.0
rem(x, y)
Return remainder (x%y). Sign of the result is same as sign of x.

julia> rem(10, -3)
1

julia> rem(-10, -3)
-1

julia> rem(-10, 3)
-1
mod(x, y)
Performs modulus after division.

julia> mod(10, -3)
-2

julia> mod(10, 3)
1

julia> mod(-10, 3)
2

julia> mod(-10, -3)
-1

julia> div(10, 0)
ERROR: DivideError: integer division error
 in div at /Applications/Julia-0.4.1.app/Contents/Resources/julia/lib/julia/sys.dylib

julia> rem(10, 0)
ERROR: DivideError: integer division error
 in rem at int.jl:80

julia> mod(10, 0)
ERROR: DivideError: integer division error
 in mod at int.jl:81






Previous                                                 Next                                                 Home

No comments:

Post a Comment