diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 517286a..cefd952 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-12T03:24:00","documenter_version":"1.3.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-16T21:17:13","documenter_version":"1.5.0"}} \ No newline at end of file diff --git a/dev/assets/README/index.html b/dev/assets/README/index.html index 9f91845..594293a 100644 --- a/dev/assets/README/index.html +++ b/dev/assets/README/index.html @@ -1,2 +1,2 @@ -
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
To use safer integers within your computations, where you have been using explict digit sequences put them inside the safe integer constructors, SafeInt(11)
or SafeUInt(0x015A)
and similarly for the bitsize-named versions SafeInt8
, SafeInt16
.. SafeInt128
and SafeUInt8
.. SafeUInt128
Where you had usedInt
or UInt
now use SafeInt
or SafeUInt
and similarly with the bitsize-named versions.
SafeInt and SafeUInt give you these arithmetic operators: +
, -
, *
, div
, rem
, fld
, mod
, ^
which have become overflow and underflow aware.
The Int and UInt types can fail at simple arithmetic and will continue carrying the incorrectness forward. So, the validity of values obtained is difficult to ascertain.
Most calculations proceed without incident, and when used SafeInts operate as Ints should a calculation encouter an overflow or underflow, we are alerted and the calculation does not proceed.
Get the package:
Pkg.add("SaferIntegers")
Use the package:using SaferIntegers
SafeInt8
, SafeInt16
, SafeInt32
, SafeInt64
, SafeInt128
SafeUInt8
, SafeUInt16
, SafeUInt32
, SafeUInt64
, SafeUInt128
SafeSigned
, SafeUnsigned
, SafeInteger
They check for overflow, even when multiplied by the usual Int and UInt types.
They do not auto-widen and are type stable. Otherwise, they are as system integers.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
To use safer integers within your computations, where you have been using explict digit sequences put them inside the safe integer constructors, SafeInt(11)
or SafeUInt(0x015A)
and similarly for the bitsize-named versions SafeInt8
, SafeInt16
.. SafeInt128
and SafeUInt8
.. SafeUInt128
Where you had usedInt
or UInt
now use SafeInt
or SafeUInt
and similarly with the bitsize-named versions.
SafeInt and SafeUInt give you these arithmetic operators: +
, -
, *
, div
, rem
, fld
, mod
, ^
which have become overflow and underflow aware.
The Int and UInt types can fail at simple arithmetic and will continue carrying the incorrectness forward. So, the validity of values obtained is difficult to ascertain.
Most calculations proceed without incident, and when used SafeInts operate as Ints should a calculation encouter an overflow or underflow, we are alerted and the calculation does not proceed.
Get the package:
Pkg.add("SaferIntegers")
Use the package:using SaferIntegers
SafeInt8
, SafeInt16
, SafeInt32
, SafeInt64
, SafeInt128
SafeUInt8
, SafeUInt16
, SafeUInt32
, SafeUInt64
, SafeUInt128
SafeSigned
, SafeUnsigned
, SafeInteger
They check for overflow, even when multiplied by the usual Int and UInt types.
They do not auto-widen and are type stable. Otherwise, they are as system integers.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
Relative to the system Integer types, using the Safer Integer types has a time cost of 1.10x..1.25x..2.00x.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
Relative to the system Integer types, using the Safer Integer types has a time cost of 1.10x..1.25x..2.00x.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
Your work may require that integer calculations be secure, well-behaved or unsurprising.
Your clients may expect your package/app/product calculates with care and correctness.
Your software may become part of a system on which the health or assets of others depends.
Your prefer to publish research results that are free of error, and you work with integers.
SaferIntegers lets you work more cleanly and always alerts otherwise silent problems.
This package is designed for easy use and written to be performant in many sorts of use.
Using SaferIntegers can preclude some known ways that insecure systems are breached.
Supports Rationals formed of SafeInteger types
Supports testing of other source code for integer safety
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
Your work may require that integer calculations be secure, well-behaved or unsurprising.
Your clients may expect your package/app/product calculates with care and correctness.
Your software may become part of a system on which the health or assets of others depends.
Your prefer to publish research results that are free of error, and you work with integers.
SaferIntegers lets you work more cleanly and always alerts otherwise silent problems.
This package is designed for easy use and written to be performant in many sorts of use.
Using SaferIntegers can preclude some known ways that insecure systems are breached.
Supports Rationals formed of SafeInteger types
Supports testing of other source code for integer safety
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
Use these exported types in place of their built-in counterparts
SafeInt
, SafeInt8
, SafeInt16
, SafeInt32
, SafeInt64
, SafeInt128
SafeUInt
, SafeUInt8
SafeUInt16
, SafeUInt32
, SafeUInt64
, SafeUInt128
These two cases are allowed to provide more flexible overflow testing with shifts and powers.
>>>
, >>
, <<
) check for overflow then return the same type as that shifted^
) check for overflow then return the same type as that of the base poweredTo check for overflow and propagate safety:
SafeInteger
on the left hand side of a shift SafeInteger
as the base number that is raised to a powerTo check for overflow only:
SafeInteger
on the right hand side of a shiftSafeInteger
as the power to which the base number is raised
+How To Use · SaferIntegers.jl How To Use
Just use safe integer types in place of the usual integer types. The rest is well handled.
To Write Code With Safe Integers
Use these exported types in place of their built-in counterparts
SafeInt
, SafeInt8
, SafeInt16
, SafeInt32
, SafeInt64
, SafeInt128
SafeUInt
, SafeUInt8
SafeUInt16
, SafeUInt32
, SafeUInt64
, SafeUInt128
Almost all ops with a SafeInteger that yield an Integer will return a SafeInteger
one shift signature and one power signature are the exceptions
These two cases are allowed to provide more flexible overflow testing with shifts and powers.
- shifts (
>>>
, >>
, <<
) check for overflow then return the same type as that shifted - powers (
^
) check for overflow then return the same type as that of the base powered
To check for overflow and propagate safety:
- use a
SafeInteger
on the left hand side of a shift - use a
SafeInteger
as the base number that is raised to a power
To check for overflow only:
- use a
SafeInteger
on the right hand side of a shift- and an unsafe integer on the left hand side
- use a
SafeInteger
as the power to which the base number is raised- and an unsafe integer as the base number
Test code for integer safety
test snippets
julia> @saferintegers begin
x = 64
y = Int16(16)
@@ -10,4 +10,4 @@
julia> typeof.(ans)
(SafeInt64, SafeInt16, SafeInt128)
test source file
julia> cd(<source file directory>)
-julia> @saferintegers include(<filename.jl>)
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
+julia> @saferintegers include(<filename.jl>)
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
Copyright ©2018-2023 by Jeffrey Sarnoff. This work is made available under The MIT License.
Using the default Int or UInt types allows overflow and underflow errors to occur silently, without notice. These incorrect values propagate and such errors are difficult to recognize after the fact.
This package exports safer versions. These types check for overflow and underflow in each of the basic arithmetic functions. The processing will stop with a message in the event of overflow or underflow. On one machine, the overhead relative to the built-in integer types is <= 1.2x.
Integer overflow occurs when an integer type is increased beyond its maximum value. Integer underflow occurs when an integer type is decreased below its minimum value. Signed and Unsigned values are subject to overflow and underflow. With Julia, you can see the rollover using Int or UInt types:
typemax(Int) + one(Int) < 0
+Overview · SaferIntegers.jl SaferIntegers
These integer types do not ignore arithmetic overflows and underflows.
Copyright ©2018-2023 by Jeffrey Sarnoff. This work is made available under The MIT License.
A Safer Way
Using the default Int or UInt types allows overflow and underflow errors to occur silently, without notice. These incorrect values propagate and such errors are difficult to recognize after the fact.
This package exports safer versions. These types check for overflow and underflow in each of the basic arithmetic functions. The processing will stop with a message in the event of overflow or underflow. On one machine, the overhead relative to the built-in integer types is <= 1.2x.
Background
Integer overflow occurs when an integer type is increased beyond its maximum value. Integer underflow occurs when an integer type is decreased below its minimum value. Signed and Unsigned values are subject to overflow and underflow. With Julia, you can see the rollover using Int or UInt types:
typemax(Int) + one(Int) < 0
typemin(Int) - one(Int) > 0
typemax(UInt) + one(UInt) == typemin(UInt)
typemin(UInt) - one(UInt) == typemax(UInt)
There are security implications for integer overflow in certain situations.
a = Int16(456) * Int16(567)
@@ -7,4 +7,4 @@
for i in 1:a
secure(biohazard[i])
-end
With a < 0
, the for
loop does not execute.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
+end
With a < 0
, the for
loop does not execute.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
SafeRational(2, 5) == SafeInt(2) // SafeInt(5)
+Safer Rationals · SaferIntegers.jl SaferRationals
Construction
SafeRational(2, 5) == SafeInt(2) // SafeInt(5)
SafeRational(SafeUInt16(2), SafeUInt16(5)) == SafeUInt16(2) // SafeUInt16(5)
-SafeRational(Int16(2), Int32(5)) == SafeInt32(2) // SafeInt32(5)
Use
Use just as you would use Julia's Rationals. These will check for overflow, though.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
+SafeRational(Int16(2), Int32(5)) == SafeInt32(2) // SafeInt32(5)
Use just as you would use Julia's Rationals. These will check for overflow, though.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
It is safe to shift (<<
, >>
) a value of type T
where `β = sizeof(T) * 8 (with SafeUnsigned value
bitsof(T)
bits, in which case the result is zero(T)
-bitsof(T)
bits, in which case the result is zero(T)
bitsof(T)-1
⦄-(bitsof(T)-1)
⦄of type T
by 0 bits (unchanged) or by ±β bits where β ∈ ⦃0, 1, .., bitsof(T)
⦄.
An OverflowError
occurs when there is an attempt to shift a value of safe type T
by a magnitude greater than ±bitsof(T)
.
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
It is safe to shift (<<
, >>
) a value of type T
where `β = sizeof(T) * 8 (with SafeUnsigned value
bitsof(T)
bits, in which case the result is zero(T)
-bitsof(T)
bits, in which case the result is zero(T)
bitsof(T)-1
⦄-(bitsof(T)-1)
⦄of type T
by 0 bits (unchanged) or by ±β bits where β ∈ ⦃0, 1, .., bitsof(T)
⦄.
An OverflowError
occurs when there is an attempt to shift a value of safe type T
by a magnitude greater than ±bitsof(T)
.
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
signbit
, sign
, abs
, abs2
count_ones
, count_zeros
leading_zeros
, trailing_zeros
, leading_ones
, trailing_ones
ndigits0z
isless
, isequal
, <=
, <
, ==
, !=
, >=
, >
>>>
, >>
, <<
, +
, -
, *
, \
, ^
div
, fld
, fld1
, cld
, rem
, mod
, mod1
divrem
, fldmod
, fldmod1
zero
, one
typemin
, typemax
, widen
Signed(x::SafeSigned)
returns an signed integer of the same bitwidth as x Unsigned(x::SafeUnsigned)
returns an unsigned integer of the same bitwidth as x Integer(x::SafeInteger)
returns an Integer of the same bitwidth and either Signed or Unsigned as is x
SafeSigned(x::Signed)
returns a safe signed integer of the same bitwidth as x SafeUnsigned(x::Unsigned)
returns a safe unsigned integer of the same bitwidth as x SafeInteger(x::Integer)
returns a safe Integer of the same bitwidth and either Signed or Unsigned as is x
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
signbit
, sign
, abs
, abs2
count_ones
, count_zeros
leading_zeros
, trailing_zeros
, leading_ones
, trailing_ones
ndigits0z
isless
, isequal
, <=
, <
, ==
, !=
, >=
, >
>>>
, >>
, <<
, +
, -
, *
, \
, ^
div
, fld
, fld1
, cld
, rem
, mod
, mod1
divrem
, fldmod
, fldmod1
zero
, one
typemin
, typemax
, widen
Signed(x::SafeSigned)
returns an signed integer of the same bitwidth as x Unsigned(x::SafeUnsigned)
returns an unsigned integer of the same bitwidth as x Integer(x::SafeInteger)
returns an Integer of the same bitwidth and either Signed or Unsigned as is x
SafeSigned(x::Signed)
returns a safe signed integer of the same bitwidth as x SafeUnsigned(x::Unsigned)
returns a safe unsigned integer of the same bitwidth as x SafeInteger(x::Integer)
returns a safe Integer of the same bitwidth and either Signed or Unsigned as is x
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.
⦃ _ ⦄ is a collection of distinct entities ordered by an intrinsic relationship and sharing an essential characteristic
⋵ ⦃ _ ⦄ selects any one within the collection, purposefully or intentlessly
𝒯 is an unsafe type
𝒮 is a built-in signed integer type
𝒰 is a built-in unsigned integer type
𝓣 is a safe type
𝓢 is a safe signed integer type
𝓤 is a safe unsigned integer type
Settings
This document was generated with Documenter.jl version 1.3.0 on Friday 12 April 2024. Using Julia version 1.10.2.
⦃ _ ⦄ is a collection of distinct entities ordered by an intrinsic relationship and sharing an essential characteristic
⋵ ⦃ _ ⦄ selects any one within the collection, purposefully or intentlessly
𝒯 is an unsafe type
𝒮 is a built-in signed integer type
𝒰 is a built-in unsigned integer type
𝓣 is a safe type
𝓢 is a safe signed integer type
𝓤 is a safe unsigned integer type
Settings
This document was generated with Documenter.jl version 1.5.0 on Friday 16 August 2024. Using Julia version 1.10.4.