Ask HN: How is it possible to get -0.0 in a sum?

gus_massa | 9 points

It depends on the FP rounding mode. If rounding mode is FE_TOWARDZERO/FE_UPWARD/FE_TONEAREST then the case you gave is the only one I'm aware of. If rounding mode is FE_DOWNWARD (towards negative infinity) then other calculations that result in a zero will give a -0.0.

Here's an example of -1.0f + 1.0f resulting in -0.0: https://godbolt.org/z/5qvqsdh9P

sparkie | 9 hours ago

What happens if we take the smallest (as in closest to zero) negative subnormal and add it to itself?

kazinator | 6 hours ago
[deleted]
| 12 hours ago