Package Extensions

Some extensions for interoperability with other packages are provided.

Random

An extension for the Base.Random package is provided, overloading rand functions. When Random is loaded, one can therefore generate random numbers just like for Floats:

using PrecisionCarriers
using Random

rand(PrecisionCarrier{Float16})
0.9673 <ε=0>
rand(PrecisionCarrier{Float32})
0.0432387 <ε=0>
rand(PrecisionCarrier)
0.003991245916783903 <ε=0>

Furthermore, when using a specific (seeded) generator, the produced values are reproducible with the non-wrapped Float generator:

@assert rand(MersenneTwister(0)) == rand(MersenneTwister(0), PrecisionCarrier)

The same is true for arrays of random numbers:

@assert rand(MersenneTwister(0), Float32, (5, 5)) == rand(MersenneTwister(0), PrecisionCarrier{Float32}, (5, 5))

DoubleFloats.jl

This is an extension for a package providing DoubleFloat types, which internally store two floats, a hi and a lo one. These can be used for better precision without resorting to larger types (which may not be supported on GPUs, for example). When this package is loaded, they can be precify'd and used just like basic Float types.

using PrecisionCarriers
using DoubleFloats

precify(df64"0.1")
9.99999999999999999999999999999996919e-02 <ε=0>
d = DoubleFloat(precify(1.0e3))
1000.0 <ε=0>
tan(atan(d))
1.00000000000000000000000000000175857e+03 <ε=36>