Eliminate the baroque floating-point operators a la !<>=
nospam at nospam.com
Sun May 17 13:01:17 PDT 2009
Denis Koroskin wrote:
> On Sun, 17 May 2009 21:14:46 +0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
>> I think the floating-point operators:
>> a !<>= b
>> a !<> b
>> a <> b
>> a <>= b
>> a !> b
>> a !>= b
>> a !< b
>> a !<= b
>> are useless. A simple peephole optimization in the compiler can
>> automatically rewrite NaN test followed by regular operations into the
>> operations above, for example:
>> isNaN(a) || isNan(b) || a >= b
>> is the same as
>> a !< b
>> This is in keeping with what the compiler does when seeing code like:
>> a = x / y;
>> b = x % y;
>> There's a peephole optimization that groups the / and the % together
>> into an assembler operation that does both. If this is the way to go, we
>> better be congruent and use explicit isNaN tests (that are then
>> optimized) instead of defining eight extra operators.
> Does anyone other than Don uses them at all?
> I don't care if they are removed from D.
Sad to say, I mostly only use !<>=, and that's because it's defined in
the language so that it works at compile time (and is unaffected by the
Tango/Phobos incompatibility problem). Also x!=x works just as well as
an isNaN test.
The silly thing is, in asm, I would never use the equivalent comparison.
In x86, for instance, a floating point < compare sets TWO flags; one for
less, one for NaN.
You almost always want to treat NaN specially, so you do one compare and
two branches. The NCEG operators only really allow you to move all of
the special cases into a single test, but you end up doing a second
comparison anyway, so it doesn't really buy you very much at all.
Inclusion of the NCEG operators was a bit of tokenism, making a _very_
strong statement that D took numerical programmers seriously. But I
think D's at the point where it can make that statement without relying
More information about the Digitalmars-d