ProtoObject and comparison for equality and ordering
Walter Bright
newshound2 at digitalmars.com
Wed May 15 17:37:10 UTC 2019
On 5/14/2019 2:06 PM, Mike Franklin wrote:
> On Tuesday, 14 May 2019 at 20:36:08 UTC, Eduard Staniloiu wrote:
>
>> Should `opCmp` return a float?
>>
>> The reason: when we attempt to compare two types that aren't comparable (an
>> unordered relationship) we can return float.NaN. Thus we can differentiate
>> between a valid -1, 0, 1 and an invalid float.NaN comparison.
>
> Seems like a job for an enum, not a float or an integer.
D used to support the 4 states with floating point comparisons. There was even a
set of operators for every case. Zero people used them. It was eventually
deprecated, sat there for years, and finally removed. (It was proposed for C,
and rejected, and C++ ignored it.)
https://www.digitalmars.com/d/1.0/expression.html#floating_point_comparisons
Not a single user spoke up for it.
Here's how people write code for unordered cases:
if (isNaN(f) || isNaN(g)) // deal with unordered cases
...
else if (f < g) // only ordered cases considered here
...
I've seen no evidence that anyone would be interested in 4 state comparisons,
and that's over two decades (yes, I implemented it in Digital Mars C++!).
I recommend we not waste time on this.
More information about the Digitalmars-d
mailing list