Check floats for .nan
Daniel Keep
daniel.keep.lists at gmail.com
Sun Oct 7 11:47:50 PDT 2007
BCS wrote:
> Reply to acarion,
>
>> I have this code:
>>
>> float number=getFloat();
>> assert(number!=float.nan); //this passes
>
> IIRC this will also pass:
>
> assert(float.nan != float.nan);
>
> this is because D used IEEE floating point semantics. Under IEEE a
> comparison with NaN will always be not equal
>
> If you want to test for nan use "testedValue !<>= 0"* or the isnan function
You can also use (x!=x) to test to see if x is NaN, and (x==x) to make
sure it is not NaN.
-- Daniel
More information about the Digitalmars-d
mailing list