# Question about floating-point precision in summation

**URL:** <https://discourse.julialang.org/t/question-about-floating-point-precision-in-summation/58334>\
**Category:** Performance\
**Tags:** question, package\
**Created:** [March 31, 2021, 10:29pm UTC](https://discourse.julialang.org/t/question-about-floating-point-precision-in-summation/58334 "2021-03-31T22:29:59Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 1, 2021, 2:10pm UTC](https://discourse.julialang.org/t/question-about-floating-point-precision-in-summation/58334/12 "2021-04-01T14:10:31Z")

</div>

> [@stevengj](#):
>
> Note that [Xsum.jl](https://github.com/JuliaMath/Xsum.jl) is actually faster than `Float64` compensated summation and is _much_ more accurate — it is equivalent to summing in infinite precision and then rounding the exact sum to `Float64` at the end.

Xsum is indeed much more accurate than any compensated summation. It is also impressively fast (especially considering the gain in accuracy), however not faster than compensated algorithms in my experience. At least not when the numbers to be summed are nicely aligned in a vector: the results shown in AccurateArithmetic.jl’s Readme illustrate how fast compensated algorithms can be when it is possible to use a SIMD-vectorized implementation. (Which may not be the case here)

> **[GitHub - JuliaMath/AccurateArithmetic.jl: Calculate with error-free,...](https://github.com/JuliaMath/AccurateArithmetic.jl)**
>
> Calculate with error-free, faithful, and compensated transforms and extended significands. - GitHub - JuliaMath/AccurateArithmetic.jl: Calculate with error-free, faithful, and compensated transform...

I also mentioned a comparison of the performances of `Base.sum`, `AccurateArithmetic.sum_oro` and `Xsum.xsum` in my talk at JuliaCon last summer:

[![](https://global.discourse-cdn.com/julialang/original/3X/6/5/65c5e63057eeaf4d8569ada2819ffe6017c4aa97.jpeg "JuliaCon 2020 | Accurate and Efficiently Vectorized Sums and Dot Products | François Févotte") ](https://www.youtube.com/watch?v=CoAlD8OqrrI&t=932)
  

> [@stevengj](#):
>
> But I continue to think that if you find yourself needing arbitrary precision in a practical computational setting there is a high probability that you are making a mistake in how you formulated your algorithm.

I entirely agree on this. The best way to solve such issues is to make them disappear entirely when possible. This may involve changes in the mathematical formulation of the problem, or changes in the resolution algorithm itself.

---

_[View the full topic](https://discourse.julialang.org/t/question-about-floating-point-precision-in-summation/58334)._
