ProtoObject and comparison for equality and ordering
Seb
seb at wilzba.ch
Wed May 15 00:57:04 UTC 2019
On Wednesday, 15 May 2019 at 00:37:25 UTC, Andrei Alexandrescu
wrote:
> On 5/14/19 1:24 AM, Seb wrote:
>> On Wednesday, 15 May 2019 at 00:08:10 UTC, Andrei Alexandrescu
>> wrote:
>>> On 5/14/19 12:36 AM, Seb wrote:
>>>> On Tuesday, 14 May 2019 at 21:06:05 UTC, 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.
>>>>>
>>>>> Mike
>>>>
>>>> +1 for enum. As far as I can see you only have four actual
>>>> states:
>>>>
>>>> lower, equal, higher, nonComparable
>>>
>>> This won't work because the result of opCmp is compared
>>> against zero. Using a floating point number is likely to be
>>> more efficient.
>>
>> A DIP should cite real evidence/data though.
>
> I'm not sure I understand. I wouldn't know how to make an enum
> even work, let alone compare against that solution. I'd be in
> your debt if you showed how.
Well, you already plan to change the compiler, so changing it to
create a different opCmp lowering when it sees this special enum
wouldn't be so hard, no?
i.e. if both opCmps return a special CompEnum, do sth. like this:
a < b => a.opCmp(b) == lowerCmp
...
There's no price to pay this way.
More information about the Digitalmars-d
mailing list