Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Julia: get max and min values of integer types


Julia provides typemin(type), typemax(type) function to get min and max values for given type.
julia> print(typemin(Int8))
-128
julia> print(typemin(Int16))
-32768
julia> print(typemin(Int32))
-2147483648
julia> print(typemin(Int64))
-9223372036854775808
julia> print(typemin(Int128))
-170141183460469231731687303715884105728
julia>

julia> print(typemin(UInt8))
0
julia> print(typemin(UInt16))
0
julia> print(typemin(UInt32))
0
julia> print(typemin(UInt64))
0
julia> print(typemin(UInt128))
0
julia>

julia> print(typemax(Int8))
127
julia> print(typemax(Int16))
32767
julia> print(typemax(Int32))
2147483647
julia> print(typemax(Int64))
9223372036854775807
julia> print(typemax(Int128))
170141183460469231731687303715884105727
julia>

julia> print(typemax(UInt8))
255
julia> print(typemax(UInt16))
65535
julia> print(typemax(UInt32))
4294967295
julia> print(typemax(UInt64))
18446744073709551615
julia> print(typemax(UInt128))
340282366920938463463374607431768211455

Integer overflow
Numbers in Julia are wrap around upon reaching maximum (or) minimum value.
julia> max=typemax(Int64)
9223372036854775807

julia> max+1
-9223372036854775808

julia> max+2
-9223372036854775807

julia>

julia> min=typemin(Int64)
-9223372036854775808

julia> min-1
9223372036854775807

julia> min-2
9223372036854775806


Reference
https://en.wikipedia.org/wiki/Modular_arithmetic




Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Julia: get max and min values of integer types

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×