Sorting floating-point values, and NaN
tn
no at email.com
Tue Nov 12 05:59:58 PST 2013
On Tuesday, 12 November 2013 at 09:40:52 UTC, Walter Bright wrote:
> On 11/12/2013 1:33 AM, tn wrote:
>> I could not find any documentation on how the unordered
>> comparison operators (<>, !<>=, !<=, !<, !>=, !>, !<>)
>> translate into opCmp calls.
>
> That's because they just don't translate to opCmp calls.
Well, they seem to translate to something, because this works as
expected:
struct S {
private double v;
auto opCmp(S rhs) { return v - rhs.v; }
}
S v1 = S(1);
S v2 = S(2);
S vn = S(double.nan);
assert((v2 < v1) == false);
assert((v1 < v2) == true);
assert((v1 < v1) == false);
assert((v1 < vn) == false);
assert((v2 !>= v1) == false);
assert((v1 !>= v2) == true);
assert((v1 !>= v1) == false);
assert((v1 !>= vn) == true);
> but then we went ahead and deprecated those operators
Maybe the spec then needs to be updated:
http://dlang.org/expression.html#RelExpression
http://dlang.org/expression.html#floating_point_comparisons
More information about the Digitalmars-d
mailing list