checking whether the number is NaN

Simen Kjaeraas simen.kjaras at
Fri Dec 28 12:19:25 PST 2012

On 2012-42-28 16:12, Zhenya <zheny at> wrote:

> Hi!
> Tell me please,are there any way to check whether number is NaN?

us std.math.isNaN. But if you really don't want to:

float x = ...;

if (x != x) {
     writeln( "x is NaN" );

I'm unsure how aggressive the optimizer is allowed to be in cases
like this. Theoretically it could assume x is always equal to x,
but I'd think it's not allowed to for floats.

If you're wondering how a float value could compare different to
the exact same value, consider that this would otherwise be true:

sqrt(-1) == 0/0


More information about the Digitalmars-d-learn mailing list