Check floats for .nan
BCS
ao at pathlink.com
Sun Oct 7 09:26:11 PDT 2007
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
> assert(to!(char[])(number)!="nan"); //this fails
> writefln(string.toString(number)); //this outputs: "nan"
> writefln( to!(char[])(to!(long)(number)) ); //this generates an error
> What did I do wrong?
>
* this is the not grater than, less than, or equal to operator.
More information about the Digitalmars-d
mailing list