Public Interface

Types

PrecisionCarriers.PrecisionCarrierType
PrecisionCarrier{AbstractFloat}

A carrier type for floating points. Most math functions are overloaded for this type. Initialize it with some value (or see precify to convert an entire array or tuple type of numbers), do some arithmetic with your value(s), and finally, print it to check the number of accumulated epsilons of error.

julia> using PrecisionCarriers

julia> function unstable(x, N)
           y = abs(x)
           for i in 1:N y = sqrt(y) end
           w = y
           for i in 1:N w = w^2 end
           return w
       end
unstable (generic function with 1 method)

julia> unstable(precify(2), 5)
1.9999999999999964 <ε=8>

julia> unstable(precify(2), 10)
2.0000000000000235 <ε=53>

julia> unstable(precify(2), 20)
2.0000000001573586 <ε=354340>

julia> unstable(precify(2), 128)
1.0 <ε=4503599627370496>
source

Functions

PrecisionCarriers.precifyFunction
precify([::Type{PrecisionCarrier{T}}], t::Any) where {T<:AbstractFloat}
precify([::Type{T}], t::Any) where {T<:AbstractFloat}

Convert a number or container to a container of PrecisionCarriers. If no specific float type for the PrecisionCarrier is specified, the type of ts floats will be used.

julia> using PrecisionCarriers

julia> precify((0, 1.0, 2.0f0))
(0.0 <ε=0>, 1.0 <ε=0>, 2.0 <ε=0>)

julia> typeof(ans)
Tuple{PrecisionCarrier{Float64}, PrecisionCarrier{Float64}, PrecisionCarrier{Float32}}

julia> precify(PrecisionCarrier{Float32}, [0, 1.0, 2.0f0])
3-element Vector{PrecisionCarrier{Float32}}:
 0.0 <ε=0>
 1.0 <ε=0>
 2.0 <ε=0>
source
PrecisionCarriers.significant_digitsFunction
significant_digits(p::PrecisionCarrier{T})

Return the number of significant decimal digits currently carried by this PrecisionCarrier.

julia> using PrecisionCarriers

julia> function unstable(x, N)
           y = abs(x)
           for i in 1:N y = sqrt(y) end
           w = y
           for i in 1:N w = w^2 end
           return w
       end
unstable (generic function with 1 method)

julia> unstable(precify(0.5), 30)
0.4999999971854335 <ε=25351362>

julia> significant_digits(ans)
8.249558460661778
source
PrecisionCarriers.reset_eps!Function
reset_eps!(p::PrecisionCarrier{AbstractFloat})

Reset the precision carrier to zero epsilons. Can be called on containers (AbstractArrays or Tuples) to reset all underlying PrecisionCarriers.

julia> using PrecisionCarriers

julia> function unstable(x, N)
           y = abs(x)
           for i in 1:N y = sqrt(y) end
           w = y
           for i in 1:N w = w^2 end
           return w
       end
unstable (generic function with 1 method)

julia> p = unstable(precify(1.5), 30)
1.4999996689838975 <ε=993842883>

julia> reset_eps!(p)
1.4999996689838975 <ε=0>

Custom types can be overloaded by implementing a function dispatching the call downwards to all relevant members. Note that this is a muting operation and therefore requires mutability of the members.

function reset_eps!(x::Custom)
    reset_eps!(x.v1)
    reset_eps!(x.v2)
    # ...
    return x
end
source
Base.eltypeFunction
Base.eltype(::PrecisionCarrier)

Return the internally carried floating point type.

source