JeffreySarnoff / SaferIntegers.jl

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

Update README.md #32

Closed LilithHafner closed 1 year ago

LilithHafner commented 1 year ago

The first change fixes a syntax error

julia> typeof(SafeInt32 + 1) == SafeInt32
ERROR: MethodError: no method matching +(::Type{SafeInt32}, ::Int64)

Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:578
  +(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}
   @ Base int.jl:87
  +(::LinearAlgebra.UniformScaling, ::Number)
   @ LinearAlgebra ~/.julia/dev/julia/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/uniformscaling.jl:144
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[32]:1

julia> typeof(SafeInt32(1) + 1) == SafeInt32
true

The second and third changes remove claims that falsely imply the unsafety of default integers.

Rationals are already checked for overflow:

help?> Rational
search: Rational rationalize Irrational SafeRational AbstractIrrational ConcurrencyViolationError ProcessFailedException

  Rational{T<:Integer} <: Real

  Rational number type, with numerator and denominator of type T. Rationals are checked for overflow.

SaferIntegers uses Base.checked_div instead of Base.div, but this is a no-op:

julia> @less Base.checked_div(7, 8)
checked_div(x::T, y::T) where {T<:Integer} = div(x, y) # Base.div already checks
...

The fourth change clarifies that the return type is a BitInteger, not an UnsafeInteger (UnsafeSigned <: Integer, so this is otherwise ambiguous)

JeffreySarnoff commented 1 year ago

Thank you -- much appreciated.