# Different Float64 sum on different architectures

**URL:** <https://discourse.julialang.org/t/different-float64-sum-on-different-architectures/46949>\
**Category:** General Usage\
**Created:** [September 20, 2020, 9:16am UTC](https://discourse.julialang.org/t/different-float64-sum-on-different-architectures/46949 "2020-09-20T09:16:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [September 20, 2020, 10:55am UTC](https://discourse.julialang.org/t/different-float64-sum-on-different-architectures/46949/4 "2020-09-20T10:55:07Z")

</div>

[Here](https://discourse.julialang.org/t/array-ordering-and-naive-summation/1929) is a fun example of the lack of associativity (thanks to Stefan Karpinski):

```julia
function sumsto(x::Float64)
    0 <= x < exp2(970) || throw(ArgumentError("sum must be in [0,2^970)"))
    n, p₀ = Base.decompose(x) # integers such that `n*exp2(p₀) == x`
    [floatmax(); [exp2(p) for p in -1074:969 if iseven(n >> (p-p₀))]
    -floatmax(); [exp2(p) for p in -1074:969 if isodd(n >> (p-p₀))]]
end

```

Example:

```julia
julia> x = sumsto(2.3);

julia> y = sumsto(1e18);

julia> sort(x) == sort(y)
true

julia> foldl(+,x)
2.3

julia> foldl(+,y)
1.0e18

```

---

_[View the full topic](https://discourse.julialang.org/t/different-float64-sum-on-different-architectures/46949)._
