TwicePrecision vs DoubleDouble



I’ve seen Base.TwicePrecision in Julia v0.6

How does this compare to package DoubleDouble?


DoubleDouble is easier to use.


Base.TwicePrecision seems to be only for storage of double precision numbers, but there seem to be hardly any math operations defined for it:

julia> x=Base.TwicePrecision(1.0,0.0)
Base.TwicePrecision{Float64}(1.0, 0.0)

julia> x*x
ERROR: MethodError: no method matching *(::Base.TwicePrecision{Float64}, ::Base.TwicePrecision{Float64})
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
  *(::Base.TwicePrecision, ::Integer) at twiceprecision.jl:469
  *(::Base.TwicePrecision{R}, ::S<:Number) where {S<:Number, R} at twiceprecision.jl:487

julia> x-x
ERROR: MethodError: no method matching -(::Base.TwicePrecision{Float64}, ::Base.TwicePrecision{Float64})
Closest candidates are:
  -(::Base.TwicePrecision) at twiceprecision.jl:82

DoubleDouble provides a full-fledged double precision number type. Or aims to do so, it appears that many mathematical functions (exp etc.) are not defined for it.


OK I’ll use DoubleDouble.

Are there any plans for a Float128?


Don’t forget DecFP128. That’s a good library.

@ScottPJones might have a wrapper for some library coming up. That will be a good stop-gap in the meantime, and I’ll test the limits of it by running it through DiffEq.

In general, there’s more work to it than you’d think. It’s useless without a Libm and so we will need a Julia-based math library for Julia-based floating point numbers to really do anything. Good thing is @pkofod is doing that for GSoC. However, even then, a lot of the functions will need to specialize on Float128 to get the right accuracy, so that will take some time and likely new implementations.

Here’s a link to some experiments I did awhile ago using different number types in DifferentialEquations.jl and seeing what worked:

You can see that it’s highly dependent on the number having a math library that’s “complete enough”. Shout out to @JeffreySarnoff’s ArbFloats.jl as a great arbitrary precision and very complete library. It’s much faster than BigFloat.


Thanks Chris for your informative reply.
Nice blog/notebook too!


The code is old and needs to be updated, but I hope it’s still helpful.