Check floats for .nan
Sean Kelly
sean at f4.ca
Sun Oct 7 16:05:18 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
I tend to use:
testedValue !<>= testedValue
Though I've occasionally wondered whether the 'is' identity operator
should work for checking against nan:
testedValue is float.nan
Sean
More information about the Digitalmars-d
mailing list