opCmp, [partial/total/pre]orders, custom floating point types etc.

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Tue Jan 12 14:26:20 PST 2016


On 01/12/2016 04:06 PM, John Colvin wrote:
> On Tuesday, 12 January 2016 at 19:50:57 UTC, Fool wrote:
>> On Tuesday, 12 January 2016 at 19:48:35 UTC, Fool wrote:
>>> On Tuesday, 12 January 2016 at 19:46:47 UTC, John Colvin wrote:
>>>> On Tuesday, 12 January 2016 at 19:44:18 UTC, Fool wrote:
>>>>> Non-reflexive '<=' does not make any sense at all.
>>>>
>>>> It might be a bit of a mess, agreed, but nonetheless:
>>>>
>>>> assert(!(float.nan <= float.nan));
>>>
>>> Agreed, but in case of float '<=' is not an order at all.
>>
>> By the way, that implies that the result of sorting an array of float
>> by default comparison is undefined unless the array does not contain NaN.
>
> Didn't think of that. Yikes. Should we change the default predicate of
> std.algorithm.sort to std.math.cmp when ElementType!R is floating point?

We're fine as we are. By default sort compares with "<". -- Andrei


More information about the Digitalmars-d mailing list