Dump special floating point operators

Don nospam at nospam.com
Fri Dec 4 08:06:31 PST 2009


ZY.Zhou wrote:
> Andrei Alexandrescu Wrote:
>> Sorry. So a !>= b is indeed semantically equivalent with isnan(a) || 
>> isnan(b) || a < b. However, if I read the table at 
>> http://www.digitalmars.com/d/2.0/expression.html#RelExpression 
>> correctly, !(a >= b) would throw if either is NaN.
>>
> 
> But there is a note under that table:
> 
>> "Exception" means the Invalid Exception is raised if one of the 
>> operands is a NAN. It does not mean an exception is thrown. 
>> Invalid Exception can be checked using the functions in std.c.fenv.

If a or b is signalling NaN (uninitialized variable), and invalid 
exceptions are unmasked, then a!>=b will generate a hardware exception 
-- showing you that you used an uninitialized variable.

isnan(a) || isnan(b) || a < b

will not raise the hardware exception.

> So I don't feel any difference between !(a>=b) and a!>=b
... but !(a>=b) will.
There's no difference between !(a>=b) and a!>=b.

Here's a table of equivalences.

a!<>=b         (a!=a) || (b!=b)
a<>b           (a==a) && (b==b) && (a!=b)
a!<>b          (a!=a) || (b!=b) || (a!=b)
a<>=b          (a==a) && (b==b)
a!<=b          !(a<=b)
a!<b           !(a<b)
a!>=b          !(a>=b)
a!>b           !(a>b)
a!>=b          !(a>=b)

Obviously if a or b is known at compile time, or if it is known not to 
be NaN, many of the <> clauses can be dropped.




More information about the Digitalmars-d mailing list