# Storage of -0.0 in sparse arrays

**URL:** <https://discourse.julialang.org/t/storage-of-0-0-in-sparse-arrays/5461>\
**Category:** Internals & Design\
**Created:** [August 19, 2017, 2:12pm UTC](https://discourse.julialang.org/t/storage-of-0-0-in-sparse-arrays/5461 "2017-08-19T14:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 19, 2017, 2:12pm UTC](https://discourse.julialang.org/t/storage-of-0-0-in-sparse-arrays/5461/1 "2017-08-19T14:12:18Z")

</div>

If I store `-0.0` as array element of a `SparseVector`, it depends on the history of modifications, whether I retrieve `-0.0` or `0.0`:

```julia
julia> A = sparse([0.0;0.0])
2-element SparseVector{Float64,Int64} with 0 stored entries
julia> A[1] = -0.0; A[1]
0.0
julia> A[1] = 1; A[1] = -0.0; A[1]
-0.0

```

While it is clear to me, why this happens, it looks like inconsistent behaviour. When I store `-0.0` I expect

- either the negative sign is always preserved
- or the `-0.0` is always replaced by `0.0`

Is that a bug or a feature? In the first case, we should change the implementation. In the second case, we should document it somehow.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [August 19, 2017, 3:05pm UTC](https://discourse.julialang.org/t/storage-of-0-0-in-sparse-arrays/5461/2 "2017-08-19T15:05:52Z")

</div>

Sparse matrix multiplication is not IEEE compliant; I suspect this is yet another manifestation of that. See [https://github.com/JuliaLang/julia/issues/22733](https://github.com/JuliaLang/julia/issues/22733)

---

<div class="post-metadata">

**Author:** ![klacru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klacru/32/27890_2.png) [@klacru](https://discourse.julialang.org/u/klacru)\
**Post date:** [August 19, 2017, 3:42pm UTC](https://discourse.julialang.org/t/storage-of-0-0-in-sparse-arrays/5461/3 "2017-08-19T15:42:04Z")

</div>

It is related, for sure! But in a way it is not the heavy `NaN` / `Inf` case.  
I do not want to make spare matrix multiplication IEEE754 compliant, but _only_ achieve a reliable store-reload behaviour, without any arithmetic considerations.  
From the remarks about `-0.0` in the link, I assume, the second option (replace `-0.0` by `0.0` during `setindex!`) would be preferred.
