-
-
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
promote(Int64(-1), Uint64(1)) yields an InexactError on v0.4 but not v0.3 #11303
Comments
Also, on 0.3: julia> uint32(-1)
0xffffffff
julia> uint64(-1)
0xffffffffffffffff
julia> convert(Uint32, -1)
0xffffffff
julia> convert(Uint64, -1)
0xffffffffffffffff On 0.4: julia> Uint32(-1)
ERROR: InexactError()
in call at /Applications/Julia-0.4.0-dev.app/Contents/Resources/julia/lib/julia/sys.dylib
julia> Uint64(-1)
ERROR: InexactError()
in call at /Applications/Julia-0.4.0-dev.app/Contents/Resources/julia/lib/julia/sys.dylib
julia> convert(Uint32, -1)
ERROR: InexactError()
in convert at /Applications/Julia-0.4.0-dev.app/Contents/Resources/julia/lib/julia/sys.dylib
julia> convert(Uint64, -1)
ERROR: InexactError()
in convert at int.jl:180 |
At least the latter parts are intended, see #8420 - kinda buried in NEWS but it's there. You might want to try |
Oh, right – I'd forgotten about those. Thanks! I'm now working on fixing up the saturating multiplication functions, which relied on conversions to extract the high 64 and low 64 bits from a Uint128. Reinterpret won't work here, since they're not the same size. Do you know what can be done instead? |
shift and convert for high bits, mask and convert for low bits maybe? |
Oh yeah! It's still valid to convert a higher-precision type into a lower-precision type if the value is within range... |
So I wonder if there's a built-in function for saying something like "the signed integer type of the same size as the unsigned integer type T". |
You can also use julia> mod(-1,UInt32)
0xffffffff
Try julia> unsigned(-1)
0xffffffffffffffff
julia> signed(typemax(UInt64))
-1 |
Good suggestions. Is there any action item on docs or a real bug here, or should we close this out? |
A test for a package of mine that passes on 0.3 fails on 0.4. I've narrowed it down to the following problem:
The problem occurs in the context of a branch-free saturating arithmetic function for subtraction that uses some bitwise tricks for speed:
The
&
call internally usespromote
, which throws the InexactError. You can callsatsub(Uint64(6), Uint64(5))
to produce the error in context.On v0.3.7, here's the result of the equivalent call to
promote
:I am not sure what the expected behavior is and the current release notes for v0.4 don't mention anything regarding this change to
promote
. Is this a desired undocumented change or a bug?If is a desired change, what should I be doing instead?
I'm running on OS X Yosemite with julia-0.4.0-c260ea92f4-osx.
The text was updated successfully, but these errors were encountered: