BAR
BAR

Reputation: 17121

How to get the maximum and minimum values of a given type

How does one get the maximum and minimum values of a Number type like an Integer or a Float?

max_value(Int)

Upvotes: 10

Views: 7867

Answers (2)

Michal
Michal

Reputation: 91

But typemax(Float64) gives 'Inf' which is probably not what the author wanted. The trick is to use prevfloat(typemax(Float64)) which is not that obvious.

julia> typemax(Float64)
Inf
julia> prevfloat(typemax(Float64))
1.7976931348623157e308

Upvotes: 7

Oscar Smith
Oscar Smith

Reputation: 6388

For questions like this, you will be best served by looking at the julia docs https://docs.julialang.org/en/v1/base/base/#Base.typemin

Specifically for this question, typemin(Int), and typemax(Int) should do what you want.

Upvotes: 20

Related Questions