[ANN] SaferIntegers for v0.7 with `^`

The latest release of SaferIntegers supports v0.7- (use an earlier release with v0.6). This release introduces a safe ^ that is very fast for bases 2:64. More tests have been added.

SaferIntegers.jl exports SafeInt64, SafeInt32, SafeUInt64 …, types that are as Int and UInt types except that arithmetic overflow throws an OverflowError. These types allow you to work with integers knowing there is no silent wrap-around or other mistake being used.

Please see the README for more information.

9 Likes

Hello, I like SafeInts. Recently I wanted to use them for Rationals, but there are some small problems:

julia> using SaferIntegers

julia> a=SafeInt(6)
6

julia> b=SafeInt(8)
8

julia> c=a//b
ERROR: checked_abs not defined for SafeInt64
Stacktrace:
 [1] error(::String, ::String, ::Type) at ./error.jl:42
 [2] no_op_err(::String, ::Type) at ./promotion.jl:388
 [3] checked_abs(::SafeInt64) at ./checked.jl:30
 [4] gcd(::SafeInt64, ::SafeInt64) at ./intfuncs.jl:25
 [5] divgcd(::SafeInt64, ::SafeInt64) at ./rational.jl:25
 [6] Rational{SafeInt64}(::SafeInt64, ::SafeInt64) at ./rational.jl:14
 [7] Rational(::SafeInt64, ::SafeInt64) at ./rational.jl:20
 [8] //(::SafeInt64, ::SafeInt64) at ./rational.jl:43
 [9] top-level scope at none:0

you can get around this error by

julia> Base.checked_abs(a::SafeInt)=abs(a)

julia> c=a//b
3//4

but there are further problems

julia> c+c
ERROR: MethodError: no method matching mul_with_overflow(::SafeInt64, ::SafeInt64)
Stacktrace:
 [1] checked_mul at ./checked.jl:287 [inlined]
 [2] +(::Rational{SafeInt64}, ::Rational{SafeInt64}) at ./rational.jl:253
 [3] top-level scope at none:0

could you have a look at it?
Thanks in advance…

Thank you for the heads up. I had not been supporting Rationals. Looking into it.

SaferIntegers v0.3.0 supports Rational{SI} where SI<:SafeInteger.

1 Like

Thanks a lot! I wanted to check the correctness of a computation using a big rational matrix. Using SafeInts
slows down the computation by 10%, compared to Ints, while using BigInts slows it by a factor of 27!