Skip to content
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

SafeUInt64(SafeUInt128(typemax(UInt64))) throws #44

Closed
LilithHafner opened this issue Mar 29, 2024 · 4 comments
Closed

SafeUInt64(SafeUInt128(typemax(UInt64))) throws #44

LilithHafner opened this issue Mar 29, 2024 · 4 comments

Comments

@LilithHafner
Copy link
Contributor

Converting a value representable as a UInt64, but not as an Int64 to SafeUInt64 can throw. For example:

julia> SafeUInt64(SafeUInt128(typemax(UInt64)))
ERROR: InexactError: trunc(Int64, 0x0000000000000000ffffffffffffffff)
Stacktrace:
 [1] throw_inexacterror(::Symbol, ::Vararg{Any})
   @ Core ./boot.jl:748
 [2] checked_trunc_sint
   @ ./boot.jl:762 [inlined]
 [3] toInt64
   @ ./boot.jl:816 [inlined]
 [4] Int64
   @ ./boot.jl:890 [inlined]
 [5] Int64
   @ ~/.julia/packages/SaferIntegers/ksnrN/src/construct.jl:83 [inlined]
 [6] SafeUInt64(x::SafeUInt128)
   @ SaferIntegers ~/.julia/packages/SaferIntegers/ksnrN/src/construct.jl:80
 [7] top-level scope
   @ REPL[11]:1
@JeffreySarnoff
Copy link
Owner

thanks --

@JeffreySarnoff
Copy link
Owner

The current fix is overwriting the source with these:

SaferIntegers.SafeUInt8(x::SafeUInt16)=baseint(SafeUInt8)(x)  
SaferIntegers.SafeUInt16(x::SafeUInt32)=baseint(SafeUInt16)(x)  
SaferIntegers.SafeUInt32(x::SafeUInt64)=baseint(SafeUInt32)(x)  
SaferIntegers.SafeUInt64(x::SafeUInt128)=baseint(SafeUInt64)(x)  

I am having difficulty with an unrelated hiccup in the automerge. So the above should work meanwhile.

JeffreySarnoff added a commit that referenced this issue Apr 12, 2024
@JeffreySarnoff
Copy link
Owner

All is copacetic with the current version 3.4.3 afaik -- I am glad you found that bug.

@LilithHafner
Copy link
Contributor Author

LilithHafner commented Apr 12, 2024

Yep. Can confirm. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants