symmetric signed types
Dominikus Dittes Scherkl
Dominikus.Scherkl at continental-corporation.com
Mon Jan 27 08:32:35 PST 2014
On Monday, 27 January 2014 at 14:13:36 UTC, Timon Gehr wrote:
> So? It was the most convenient way to illustrate that I have
> defined a not fully ordered type using opCmp.
Was not my idea to deprecate them :-/
>
>> And you cannot opverload opCmp in a way that the new defined
>> integer NaN
>> will not compare in some way to the other integer values.
>
> Of course you can. Just return float.nan from opCmp in the case
> that at least one of the arguments is your 'integer NaN'.
>
> float opCmp(sint r){
> if(isNan()||r.isNan()) return float.nan;
> return value<r.value?-1:value>r.value?1:0;
> }
>
>> What would be needed is a minimal signed type (2bit with the
>> values -1,
>> 0, 1 and NaN) and use that in opCmp.
>
> That's not needed in order to get correct comparison behaviour.
Ah, ok. Now I understand. not inventing a type with NaN, but
instead using one that provides it - really a nice trick. I never
thought of a comparison operator returning a float.
Cool. Thank you very much.
More information about the Digitalmars-d
mailing list