Thread overview
[Issue 13663] Comparison of Tuples with floating point fields
Dec 14, 2014
Peter Alexander
Dec 04, 2019
berni44
Dec 04, 2019
Simen Kjaeraas
Dec 04, 2019
berni44
Dec 04, 2019
Dlang Bot
Dec 21, 2019
berni44
Jan 17
Dlang Bot
Jan 19
Dlang Bot
December 14, 2014
https://issues.dlang.org/show_bug.cgi?id=13663

Peter Alexander <peter.alexander.au@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au@gmail.co
                   |                            |m

--- Comment #1 from Peter Alexander <peter.alexander.au@gmail.com> ---
There is nothing that can be done here. For user defined types (e.g. Tuple), comparison operators are converted to calls to opCmp, i.e.

a < b    a.opCmp(b) < 0
a <= b    a.opCmp(b) <= 0
a > b    a.opCmp(b) > 0
a >= b    a.opCmp(b) >= 0

For NaN vs NaN, the comparison is neither equal, less than, nor greater than. There is nothing that opCmp can return to give the desired semantics.

--
December 04, 2019
https://issues.dlang.org/show_bug.cgi?id=13663

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@d-ecke.de
         Resolution|---                         |WONTFIX

--- Comment #2 from berni44 <bugzilla@d-ecke.de> ---
I cannot even see a place, where this can be clearified in the docs. Maybe in some very general place, like some page on floating point numbers in general.

--
December 04, 2019
https://issues.dlang.org/show_bug.cgi?id=13663

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |simen.kjaras@gmail.com
         Resolution|WONTFIX                     |---

--- Comment #3 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
Peter's claims in comment 1 are plain false - opCmp can return float, and float.nan for incomparable cases. Here's an implementation of opCmp that does that:

        float opCmp(R)(R rhs)
        if (areCompatibleTuples!(typeof(this), R, "<"))
        {
            static foreach (i; 0 .. Types.length)
            {
                if (field[i] != field[i] || rhs.field[i] != rhs.field[i])
                {
                    return float.nan;
                }
                if (field[i] != rhs.field[i])
                {
                    return field[i] < rhs.field[i] ? -1 : 1;
                }
            }
            return 0;
        }

        /// ditto
        float opCmp(R)(R rhs) const
        if (areCompatibleTuples!(typeof(this), R, "<"))
        {
            static foreach (i; 0 .. Types.length)
            {
                if (field[i] != field[i] || rhs.field[i] != rhs.field[i])
                {
                    return float.nan;
                }
                if (field[i] != rhs.field[i])
                {
                    return field[i] < rhs.field[i] ? -1 : 1;
                }
            }
            return 0;
        }

These are taken directly from std.typecons, and the only change made is they return float, and check if any of the fields are incomparable.

--
December 04, 2019
https://issues.dlang.org/show_bug.cgi?id=13663

--- Comment #4 from berni44 <bugzilla@d-ecke.de> ---
(In reply to Simen Kjaeraas from comment #3)
> opCmp can return float

Oh, I didn't know that trick with returning nan. I'll check your solution and add a PR.

--
December 04, 2019
https://issues.dlang.org/show_bug.cgi?id=13663

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@berni44 created dlang/phobos pull request #7301 "Fix Issue 13663 - Comparison of Tuples with floating point fields" fixing this issue:

- Fix Issue 13663 - Comparison of Tuples with floating point fields

https://github.com/dlang/phobos/pull/7301

--
December 21, 2019
https://issues.dlang.org/show_bug.cgi?id=13663

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--- Comment #6 from berni44 <bugzilla@d-ecke.de> ---
*** Issue 18832 has been marked as a duplicate of this issue. ***

--
January 17
https://issues.dlang.org/show_bug.cgi?id=13663

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@berni44 created dlang/phobos pull request #7748 "Fix Issue 13663 - Comparison of Tuples with floating point fields" fixing this issue:

- Fix Issue 13663 - Comparison of Tuples with floating point fields

https://github.com/dlang/phobos/pull/7748

--
January 19
https://issues.dlang.org/show_bug.cgi?id=13663

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #7748 "Fix Issue 13663 - Comparison of Tuples with floating point fields" was merged into master:

- ab2f7cdef4d80964a85440699b358fb95b50b26f by Bernhard Seckinger:
  Fix Issue 13663 - Comparison of Tuples with floating point fields

https://github.com/dlang/phobos/pull/7748

--