# TwicePrecision vs DoubleDouble

**URL:** https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149
**Category:** General Usage
**Tags:** question
**Created:** [June 7, 2017, 10:16pm UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149 "2017-06-07T22:16:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [June 7, 2017, 10:16pm UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/1 "2017-06-07T22:16:36Z")

</div>

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

How does this compare to package `DoubleDouble`?

---

<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: [June 8, 2017, 2:10am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/2 "2017-06-08T02:10:36Z")

</div>

DoubleDouble is easier to use.

---

<div class="post-metadata">

### Author: ![traktofon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/traktofon/32/591_2.png) [@traktofon](https://discourse.julialang.org/u/traktofon)
#### Post date: [June 8, 2017, 2:19am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/3 "2017-06-08T02:19:18Z")

</div>

`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
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.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [June 9, 2017, 4:16am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/4 "2017-06-09T04:16:07Z")

</div>

OK I’ll use `DoubleDouble`.

Are there any plans for a `Float128`?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 9, 2017, 5:04am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/5 "2017-06-09T05:04:29Z")

</div>

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

> [@greg\_plowman](#):
>
> Are there any plans for a Float128?

@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:

[http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqTutorials.jl/blob/master/ExtraODEFeatures/Solving%20Equations%20in%20With%20Julia-Defined%20Types.ipynb](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqTutorials.jl/blob/master/ExtraODEFeatures/Solving%20Equations%20in%20With%20Julia-Defined%20Types.ipynb)

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.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [June 9, 2017, 5:57am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/6 "2017-06-09T05:57:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 9, 2017, 6:06am UTC](https://discourse.julialang.org/t/twiceprecision-vs-doubledouble/4149/7 "2017-06-09T06:06:51Z")

</div>

> [@greg\_plowman](#):
>
> Nice blog/notebook too!

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