Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

julia

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

max_value(Int)
like image 673
BAR Avatar asked Jul 31 '19 06:07

BAR


2 Answers

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.

like image 168
Oscar Smith Avatar answered Sep 23 '22 09:09

Oscar Smith


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
like image 22
Michal Avatar answered Sep 24 '22 09:09

Michal