JuliaMath / FixedPointNumbers.jl

fixed point types for julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overflow in `N63f1(Float64(typemax(N63f1)))` and so on

kimikage opened this issue · comments

For example:

julia> N63f1(prevfloat(2.0^64))
1.8446744073709548e19N63f1

julia> N63f1(2.0^64)
9.223372036854776e18N63f1

The overflow itself occurs here.

ex != -1 || signbit(signed(yi)) && return typemax(N)
return reinterpret(N, unsafe_trunc(T, yi + yi))

However, this is essentially problem with the typemax.

julia> 2.0^64 > typemax(N63f1) # clearly `2^64` is out of range
true

I already know that we have this kind of problem, and in fact I have added the special handling for the cases of N0f64 and Float16.

I forgot about this issue, but the tests on ARM seem to "correctly" fail in this regard.

Apparently there are multiple issues. I limited the scope of this issue to the simple problem, i.e. the cases where f == 1.

julia> N31f1(2.0f0^32)
2.147483648e9N31f1

julia> Normed{UInt128,1}(prevfloat(2.0^128))
3.402823669209384e38N127f1

julia> Normed{UInt128,1}(2.0^128)
1.7014118346046923e38N127f1

Perhaps I identified the other issue.

julia> BigFloat(typemax(UInt64))|>N63f1 # x86-64 / i686 
1.8446744073709552e19N63f1

julia> BigFloat(typemax(UInt64))|>N63f1 # Aarch64 / ARMv7
9.223372036854776e18N63f1