JeffreySarnoff / SaferIntegers.jl

These integer types use checked arithmetic, otherwise they are as system types.
MIT License
59 stars 10 forks source link

Overflow not captured ? #16

Closed Marlin-Na closed 3 years ago

Marlin-Na commented 4 years ago

Hi I just started trying this package, but it seems not capturing overflow of 100^10?

julia> SafeInt(100)^9
1000000000000000000

julia> SafeInt(100)^10
7766279631452241920

julia> SafeInt(100)^11
ERROR: OverflowError: 100^11
JeffreySarnoff commented 4 years ago

We, the SaferIntegers User Community, are grateful for your attention to detail. I, the package author, am on the fix. Thank you for the bug report.

JeffreySarnoff commented 4 years ago

notes isolating the bug in these cases, equivalent after implicit promotion: SafeInteger(b)^p, b^SafeInteger(p), SafeInteger(b)^SafeInteger(p) where SafeInteger(x::Union{Signed,Unsigned}) = convert(SafeInteger, x)

The bug in b^p occurs when the power is p == 10 and the base b small enough to dispatch through table lookup. The most prudent approach is to regenerate all of the powering tables using a dynamically adjusting validity check to trap and report any case where an incorrect outcome is reported -- presuming no such cases arise, the fix fixed it.

JeffreySarnoff commented 3 years ago

fixed