# SaferIntegers v3

**URL:** <https://discourse.julialang.org/t/saferintegers-v3/68013>\
**Category:** Community\
**Tags:** package, numbers, update, integer-overflow\
**Created:** [September 11, 2021, 1:43am UTC](https://discourse.julialang.org/t/saferintegers-v3/68013 "2021-09-11T01:43:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [September 11, 2021, 1:43am UTC](https://discourse.julialang.org/t/saferintegers-v3/68013/1 "2021-09-11T01:43:47Z")

</div>

[SaferIntegers.jl](https://github.com/JeffreySarnoff/SaferIntegers.jl) version 3 exists. The exported abstract types `SafeInteger`, `SafeSigned`, `SafeUnsigned` are now defined as originally intended – Julia’s advancement, the active pursuit of consistant type abstractions, made it easy.

```julia
SafeUnsigned <: Unsigned
SafeSigned <: Signed
SafeInteger <: Integer

```

This clean approach holds through the exported concrete types.

```julia
SafeUInt <: SafeUnsigned <: Unsigned <: Integer <: Real
SafeInt <: SafeSigned <: Signed <: Integer <: Real

```

A good deal of benchmarking was done to evaluate the appropriateness of using SaferIntegers with [Ratios.jl](https://discourse.julialang.org/https://github.com/timholy/Ratios.jl).to protect calculations within [Interpolations.jl](https://github.com/JuliaMath/Interpolations.jl) from [Integer overflow in innocent looking linear interpolation](https://github.com/JuliaMath/Interpolations.jl/issues/457) without warning. The results are compelling, encouraging their wider application.

> Using SafeInt64s with Ratios requires 1.025 the time used with Int64 Ratios. That is a laudable return on time invested (an extra 1.5 seconds minute).
> 
> [see Ratios/pull/23](https://github.com/timholy/Ratios.jl/pull/23) for details.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 11, 2021, 1:57am UTC](https://discourse.julialang.org/t/saferintegers-v3/68013/2 "2021-09-11T01:57:05Z")

</div>

What are the mane differences between v3 and v2?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [September 11, 2021, 2:37am UTC](https://discourse.julialang.org/t/saferintegers-v3/68013/3 "2021-09-11T02:37:39Z")

</div>

The formal distinction is in the creation of the abstract types, and so the inheritance hierarchy that pervades the concrete types.

The new way is much cleaner and makes reasoning about the abstract inheritance relationships and their concrete realizations much simpler.

The old way was a result of earlier internal limitations that Julia’s type patterning had embedded in the way Unsigned and Signed integer types had been developed (well, implemented). This forced defining these abstract types:

```julia
abstract type SafeInteger <: Integer end
abstract type SafeUnsigned <: SafeInteger end
abstract type SafeSigned <: SafeInteger end

```

So it precluded the natural type abstraction pattern and Type logic we have now. For example, it had been the case that `!(SafeUnsigned <: Unsigned)`.

There are some additional changes.

- Several bugs (limited to small yet substantive subdomains) are fixed.  
They were found by a few careful users whom I thank for the assist.
- `float(x::SafeInteger)` now works to mirror `float(x::Integer)`  
This provides cross-package support and reduces others’ effort.
- There are other inconspicuous improvements that just work.
