Range behavior for Float32

Float32 is no longer accurate for such large number (not a Julia problem, I’m using 1.8.1, no version will “fix”, just in general an expected problem with IEEE floats, eventually if large enough):

julia> Int64(Float32(23_849_999))
23850000

I believe this is one reason for LinRange. So use that or respect:

julia> maxintfloat(Float64)
9.007199254740992e15

julia> Int64(maxintfloat(Float32))  # last accurate integer to last digit, much smaller than last (inaccurate) integer
16777216

julia> BigInt(floatmax(Float32))  # a bit deceiving
340282346638528859811704183484516925440
2 Likes