-0.0 == 0.0, but issorted([0.0, -0.0]) returns false

heliosdrm
Wed, 23 Jul 2025 07:18:10 +0000
General Usage

There is some kind of sorting order between positive and negative zeros of float types:

julia> issorted([-0.0, 0.0])
true

julia> issorted([0.0, -0.0])
false

But this is not observed when those numbers are compared to each other:

julia> -0.0 < 0.0
false

julia> -0.0 > 0.0
false

julia> -0.0 == 0.0
true

I understand the convenience of treating -0.0 and 0.0 as equal, but in that case, should not issorted([0.0, -0.0]) return true?

(Side note: this apparent inconsistency happens with float types, but not with integers because -0 === 0.)

5 posts - 3 participants