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

**URL:** <https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966>\
**Category:** General Usage\
**Tags:** sorting, comparison\
**Created:** [July 23, 2025, 7:18am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966 "2025-07-23T07:18:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [July 23, 2025, 7:18am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966/1 "2025-07-23T07:18:10Z")

</div>

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

```julia
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
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`.)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 23, 2025, 7:23am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966/2 "2025-07-23T07:23:43Z")

</div>

Sorting uses `isless` by default, not `<`. The analogue to `==` is `isequal`, and that docstring does explicitly mention the distinction between -0.0 and 0.0, which is mandated by IEEE-754 for total ordering. You can input `<` for IEEE-754 comparisons instead, but that also violates equivalence transitivity for incomparability `!lt(x, y) && !lt(y, x)` (not equality `==`, that’s a different equivalence relation):

```julia
julia> issorted([0.0, -0.0], lt=<)
true

```

Transitivity is critical for sorting because algorithms can avoid redundantly comparing all pairs; comparing A vs B then B vs C should make B vs C unnecessary. The docstring of `sort!` gives an example of `NaN` vs `1.0` and `NaN` vs `2.0` being incomparable under `<` yet `1.0 < 2.0`, and even if we don’t care where `NaN` goes, we can still get an unacceptable sorting failure:

```julia
julia> sort!([2.0, NaN, 1.0], lt=<) |> println
[2.0, NaN, 1.0]

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [July 23, 2025, 7:35am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966/3 "2025-07-23T07:35:43Z")

</div>

> [@Benny](#):
>
> If you want, you can use `<` instead

This is contrary to the documentation, so there could be big caveats. `<` is not a strict weak order, and is explicitly mentioned as not valid for the case of `Float64`.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 23, 2025, 7:39am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966/4 "2025-07-23T07:39:07Z")

</div>

Good catch, amended.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [July 23, 2025, 8:43am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966/5 "2025-07-23T08:43:44Z")

</div>

I was not aware of the difference between `<` and `isless`. This makes it clear. Thank you!
