New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion of number to Posit8 returns NaR #73
Comments
julia> Posit8(1e8)
Posit8(1.6777216e7)
julia> Posit8(1e9)
NaR
julia> Posit8(1e10)
Posit8(1.6777216e7) So there's a "bad spot" where the conversion of x>maxpos is to NaR instead of to maxpos. Beyond that conversion returns maxpos correctly. Testing this more thoroughly julia> for T in (Posit8,Posit16,Posit16_1,Posit32)
for x in 5:0.1:100
~isfinite(T(10.0 ^ x)) && println((T,x,:overflow))
iszero(T(10.0 ^-x)) && println((T,x,:underflow))
end
end
(Posit8, 8.5, :overflow)
(Posit8, 8.6, :overflow)
(Posit8, 8.7, :overflow)
(Posit8, 8.8, :overflow)
(Posit8, 8.9, :overflow)
(Posit8, 9.0, :overflow)
(Posit8, 9.1, :overflow)
(Posit8, 9.2, :overflow)
(Posit8, 9.3, :overflow)
(Posit8, 9.4, :overflow)
(Posit8, 9.5, :overflow)
(Posit8, 9.6, :overflow)
(Posit16, 18.1, :overflow)
(Posit16, 18.2, :overflow)
(Posit16, 18.3, :overflow)
(Posit16, 18.4, :overflow)
(Posit16, 18.5, :overflow)
(Posit16, 18.6, :overflow)
(Posit16, 18.7, :overflow)
(Posit16, 18.8, :overflow)
(Posit16, 18.9, :overflow)
(Posit16, 19.0, :overflow)
(Posit16, 19.1, :overflow)
(Posit16, 19.2, :overflow)
(Posit16_1, 9.1, :overflow)
(Posit16_1, 9.2, :overflow)
(Posit16_1, 9.3, :overflow)
(Posit16_1, 9.4, :overflow)
(Posit16_1, 9.5, :overflow)
(Posit16_1, 9.6, :overflow)
(Posit32, 37.4, :overflow)
(Posit32, 37.5, :overflow)
(Posit32, 37.6, :overflow)
(Posit32, 37.7, :overflow)
(Posit32, 37.8, :overflow)
(Posit32, 37.9, :overflow)
(Posit32, 38.0, :overflow)
(Posit32, 38.1, :overflow)
(Posit32, 38.2, :overflow)
(Posit32, 38.3, :overflow)
(Posit32, 38.4, :overflow)
(Posit32, 38.5, :overflow) So each posit format with 2 exponent bits has about 1 decade of overflow, Posit16,1 has half a decade of overflow. By refining the range, it seems that overflow occurs between
With SoftPosit.jl/src/conversions.jl Lines 109 to 111 in 73d44d7
Line 111 here |
Turns out only a small change was needed to correct for this. The only test that's currently not passing is julia> Posit32(Inf32)
Posit32(0.0)
julia> Posit32(-Inf32)
Posit32(0.0)
julia> Posit32(NaN32)
Posit32(0.0)
julia> Posit32(-NaN32)
Posit32(0.0) So only Float32 -> Posit32 the non-finite numbers do something odd. I need to look into this. |
Then there's apparently also this issue remaining (similar for other formats) julia> Posit8(1f-8)
Posit8(9.536743e-7)
julia> floatmin(Posit8)
Posit8(5.9604645e-8) Meaning that a float-value that should be converted to floatmin/minpos of posit, it actually gets converted to the next larger posit. |
And the issue as already descriped in the issue remains julia> Posit8(floatmin(Float32))
Posit8(0.0)
julia> Posit8(10*floatmin(Float32))
Posit8(5.9604645e-8) floats within a multiple of floatmin underflow instead of being converted to floatmin/minpos of the posit format. |
Hello,
I found unexpected results when converting a normal floating point number to a Posit8, I believe a large number should return max_posit instead of NaR
Have a nice day
The text was updated successfully, but these errors were encountered: