-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Reinterpreting bit pattern as Float64 corrupts it on 32-bit Windows #17195
Comments
The failure only affected Julia 0.5 for some reason, despite the existence of (one symptom of) the bug on 0.4. See JuliaLang/julia#17195.
On 0.4.6 32-bit Windows, the same corruption also occurs in this example: julia> b=IOBuffer([0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xa2])
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=f
alse, size=8, maxsize=Inf, ptr=1, mark=-1)
julia> x=map(ntoh, read(b, Float64, 1))
1-element Array{Float64,1}:
NaN
julia> reinterpret(UInt64, x)
1-element Array{UInt64,1}:
0x7ff80000000007a2 On 0.5, this no longer happens (I get EDIT: funny fact: 0.4.6 was consistent in the corruption, so that the DataFrames code parsing R data files worked, while in 0.5 it fails because of the discrepancy. See JuliaData/DataFrames.jl#1006. |
The failure only affected Julia 0.5 for some reason, despite the existence of (one symptom of) the bug on 0.4. See JuliaLang/julia#17195.
The failure only affected Julia 0.5 since on 0.4.6 the corruption happened everywhere: the bit pattern was consistent and comparisons worked. See JuliaLang/julia#17195.
Same issue as #18019 (comment) As noted in that issue, this is a hardware/abi limit and there's little(nothing?) we can do to fix this. |
Note that this isn't a hardware limit: this behavior is formally specified by the IEEE spec that this bit should get set when the value is interpreted as a float. (although the spec says nothing about whether compiler optimizations may remove the presence of the potentially costly bitcasts). Additionally, according to the spec, all values |
Can we fix the discrepancy between reinterpreting a scalar and reinterpreting an array, though? On 0.4.6, the "corruption" also happened with arrays, but that's no longer the case in 0.5. This is confusing and doesn't looks like it follows the IEEE spec. |
Not really, no matter what the ieee spec says, the value is corrupted whenever it hits the x87 stack which is really hard to avoid when it's part of the ABI. |
Yeah, but what I'm missing is why it isn't corrupted when reinterpreting an array on 0.5, while it was corrupted on 0.4. I would find it better to always corrupt, so at least it would be consistent. |
Special case these two cases might be possible (but hard and almost certainly add overhead to unrelated cases), but not when this appears in other context so I don't think it's useful at all. |
My point above is that this isn't corruption. It is well-defined what should happen to the value, it is simply undefined when it should happen. A combination of compiler optimizations and platform ABI is permitted to pick a behavior based on whatever is more efficient. |
Yeah, that's why I used quotes around "corruption". Anyway, if it's not possible to make this happen in all cases, probably not worth spending time on adjusting some of them. |
The failure only affected Julia 0.5 since on 0.4.6 the corruption happened everywhere: the bit pattern was consistent and comparisons worked. See JuliaLang/julia#17195.
The failure only affected Julia 0.5 since on 0.4.6 the corruption happened everywhere: the bit pattern was consistent and comparisons worked. See JuliaLang/julia#17195.
Reinterpreting a bit pattern as
Float64
leads to its corruption on 32-bit Windows, both on git master and on 0.4.6. This doesn't happen on 64-bit Windows, nor on 32-bit Linux.Simplest reproducer:
Putting the value in an array fixes the problem:
The text was updated successfully, but these errors were encountered: