# DoubleFloats.jl -\> Double128 | Quad64?

**URL:** <https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049>\
**Category:** Numerics\
**Created:** [December 1, 2020, 3:33pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049 "2020-12-01T15:33:07Z")\
**Posts on this page:** 15\
**Page:** 3

<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:** [December 8, 2020, 11:46am UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/41 "2020-12-08T11:46:22Z")

</div>

yes

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [December 8, 2020, 11:49am UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/42 "2020-12-08T11:49:17Z")

</div>

Ok thanks ! I’ll try that using some multiple dispatch on the type. Hopefuly it’ll reduce the runtie of bigfloats, i’ll tell you by how much as soon as possible.

---

<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:** [December 8, 2020, 11:57am UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/43 "2020-12-08T11:57:38Z")

</div>

> [@lrnv](#):
>
> x += z \* y \* t

```julia
function xzyt(tmp::T, tmp2::T, x::T, y::T, z::T, t::T) where T<:BigFloat
  mul!(tmp, z, y)
  mul!(tmp2, tmp, t)
  add!(tmp, tmp2, x)
  return tmp
end

```

similarly for your other case with another multiply

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [December 8, 2020, 1:08pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/44 "2020-12-08T13:08:13Z")

</div>

Well @JeffreySarnoff thanks a lot for taking the time, but sadly i did not see any notable improvements from these. Maybe I misused them though.

What is your oppinon on [exp/log for MultiFloats.jl](https://github.com/dzhang314/MultiFloats.jl/issues/7) ? I think this package is the way to go for me, regarding the speedup for 256ish bits of precision, although it seems like no updates have been made these past 5 months.

---

<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:** [December 8, 2020, 1:14pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/45 "2020-12-08T13:14:19Z")

</div>

@lmrv I have no opinion about MultiFloats. `exp` and `log` have to be coded for the precision in use, unless variable precision algorithms are used (BigFloat, ArbNumerics). It is difficult to do correctly for new precisions.

Are you reusing the same temporary BigFloats? Doing that should speed things some.

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [December 8, 2020, 1:25pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/46 "2020-12-08T13:25:38Z")

</div>

> [@JeffreySarnoff](#):
>
> I have no opinion about MultiFloats. `exp` and `log` have to be coded for the precision in use, unless variable precision algorithms are used (BigFloat, ArbNumerics). It is difficult to do correctly for new precisions.

Okay so I clearly wont be able to do it myself.

> [@JeffreySarnoff](#):
>
> Are you reusing the same temporary BigFloats? Doing that should speed things some.

Yes I am 😟

---

<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:** [December 8, 2020, 1:31pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/47 "2020-12-08T13:31:52Z")

</div>

[Arblib.jl](https://github.com/kalmarek/Arblib.jl) supports `exp` and `log` along with arithmetic. And the default precision is 256 bits. Give it a try with your code, if you have not yet (ignore the warning).

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [December 8, 2020, 1:33pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/48 "2020-12-08T13:33:40Z")

</div>

> [@JeffreySarnoff](#):
>
> [Arblib.jl](https://github.com/kalmarek/Arblib.jl) supports `exp` and `log` along with arithmetic. And the default precision is 256 bits. Give it a try with your code, if you have not yet (ignore the warning).

Arblib tests are a work in progress (see [this issue](https://github.com/kalmarek/Arblib.jl/issues/101))

---

<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:** [December 8, 2020, 1:37pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/49 "2020-12-08T13:37:39Z")

</div>

I did not see that you needed `expm1`. You could try without it. Otherwise, I am out of directions for you.

---

<div class="post-metadata">

**Author:** ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)\
**Post date:** [December 8, 2020, 1:39pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/50 "2020-12-08T13:39:34Z")

</div>

> [@JeffreySarnoff](#):
>
> Otherwise, I am out of directions for you.

You already helped a lot ! Thanks for all. I will try ArbLib as soon as i have some time, but for the moment it seems like MultiFloats is fastr than everything for these kind of precisions, even with the conversion to bigfloat for transcendental functions;

---

<div class="post-metadata">

**Author:** ![abulak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abulak/32/28314_2.png) [@abulak](https://discourse.julialang.org/u/abulak)\
**Post date:** [December 8, 2020, 9:19pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/51 "2020-12-08T21:19:44Z")

</div>

As of v0.2.1 `Arblib` already extends `expm1` (it was under `Arblib.expm1!`, just not hooked to `Base.expm1`); Let me know when/if you need something more.

@JeffreySarnoff what was your rationale for defining `eps` as you did in `ArbNumerics`? In here: [https://github.com/kalmarek/Arblib.jl/issues/101#issuecomment-738653420](https://github.com/kalmarek/Arblib.jl/issues/101#issuecomment-738653420) I have three equally valid implementations (or at least that’s how I see it:)

---

<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:** [December 13, 2020, 8:26pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/52 "2020-12-13T20:26:21Z")

</div>

@abulak because I defined both `ulp` and `eps` where  
`eps(x) = 2*ulp(x)`. Perhaps I should have swapped the names, perhaps not. There is a distinction in at least some of the literature.

note:

```julia
void arf_mag_set_ulp(mag_t res, const arf_t x, slong prec)
    Sets res to the magnitude of the unit in the last place
    (ulp) of x at precision prec.
``
```

---

<div class="post-metadata">

**Author:** ![abulak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abulak/32/28314_2.png) [@abulak](https://discourse.julialang.org/u/abulak)\
**Post date:** [December 14, 2020, 11:46am UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/53 "2020-12-14T11:46:44Z")

</div>

for one thing: why `2*ulp`?

> `eps(x::AbstractFloat)`
> 
> Return the **unit in last place** (ulp) of x. This is the distance between consecutive representable floating point values at `x`. In most cases, if the distance on either side of `x` is different, then the larger of the two is taken

I thought `Arblib`s `ulp` takes care of it? Also you set `eps(x::ArbFloat)` to a small ball centered at `eps(midpoint of x)`. Why this, and not a ball centered at `0` of radius `eps(midpoint of x)`?

---

<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:** [December 14, 2020, 12:59pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/54 "2020-12-14T12:59:25Z")

</div>

As mentioned, swapping those names (eps, ulp) may be preferred.  
I adopted an academic distinction rather than moving within the standard Julia terminology – and this is worth revisiting shortly.

> you set `eps(x::ArbFloat)` to a small ball centered at `eps(midpoint of x)` . Why this, and not a ball centered at `0` of radius `eps(midpoint of x)` ?

_using what I had called `ulp(x)` or, equivalently my `eps(x)/2`_:

```julia
...
w = Mag()
# Sets w to the magnitude of the ulp of x at precision P
# typeof(w) is Mag
 ccall(@libarb(arf_mag_set_ulp), Cvoid, (Ref{Mag}, Ref{ArbFloat}, Clong), w, x, P)
# Converts w to an ArbFloat, `z`, so z has magnitude w
# and, thus, z == the ulp of x 
z = ArbFloat{P}(w)
...

```

`arf_mag_set_ulp` is a direct call into the Arb C library. This is preferable to deriving the `ulp` more indirectly, or directly with more than one access to the library. Often, internals of the library compensate for corner cases and handle other subtle effects that are not easily fully available to the C programming interface. As a matter of course, I have learned to prefer this approach.

---

<div class="post-metadata">

**Author:** ![abulak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abulak/32/28314_2.png) [@abulak](https://discourse.julialang.org/u/abulak)\
**Post date:** [December 14, 2020, 11:10pm UTC](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049/55 "2020-12-14T23:10:39Z")

</div>

Ok, maybe now i understand your `ulp`/`eps`. To clarify the second question: there are (at least) three tentative definitions of `ulp` as an `Arb` (or `ArbReal`) i can come up with:

```julia
w = Mag()
res = Arb(prec=precision(x))
Arblib.set!(res, Arblib.set_ulp!(w, Arblib.midref(x), precision(x))
# res is a ball centered at ulp(x) with the appropriate radius

```

and

```julia
res = Arb(prec=precision(x))
Arblib.set_ulp!(Arblib.radref(res), Arblib.midref(x), precision(x))
# res is a ball centered at 0 with radius ulp(x)

```

and

```julia
res = Arb(prec=precision(x))
Arblib.set_ulp!(Arblib.radref(res), Arblib.midref(x), precision(x))
Arblib.set!(Arblib.midref(res), Arblib.radref(res))
Arblib.zero!(Arblib.radref(res))
# res is a ball centered at ulp(x) with radius 0

```

Was there any particular reason why did you go for the first one?

[Previous page](https://discourse.julialang.org/t/doublefloats-jl-double128-quad64/51049.md?page=2)
