## digitalmars.D.learn - checking whether the number is NaN

• Zhenya (2/2) Dec 28 2012 Hi!
• bearophile (4/5) Dec 28 2012 http://dlang.org/phobos/std_math.html#isNaN
• Zhenya (2/8) Dec 28 2012 Thank you!
• Red (5/8) Dec 28 2012 pure nothrow @trusted bool isNaN(real x);
• Simen Kjaeraas (14/16) Dec 28 2012 us std.math.isNaN. But if you really don't want to:
• Zhenya (3/20) Dec 28 2012 Thank you,understood)
"Zhenya" <zheny list.ru> writes:
```Hi!
Tell me please,are there any way to check whether number is NaN?
```
Dec 28 2012
"bearophile" <bearophileHUGS lycos.com> writes:
```Zhenya:

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

http://dlang.org/phobos/std_math.html#isNaN

Bye,
bearophile
```
Dec 28 2012
"Zhenya" <zheny list.ru> writes:
```On Friday, 28 December 2012 at 15:59:35 UTC, bearophile wrote:
Zhenya:

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

http://dlang.org/phobos/std_math.html#isNaN

Bye,
bearophile

Thank you!
```
Dec 28 2012
"Red" <resmith lavabit.com> writes:
``` Tell me please,are there any way to check whether number is
NaN?

http://dlang.org/phobos/std_math.html#isNaN

pure nothrow  trusted bool isNaN(real x);

Returns !=0 if e is a NaN.

-------------------
Seems like a slight documentation disagreement. Shows bool
prototype but description says returns !=0
```
Dec 28 2012
"Simen Kjaeraas" <simen.kjaras gmail.com> writes:
```On 2012-42-28 16:12, Zhenya <zheny list.ru> 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

--
Simen
```
Dec 28 2012
"Zhenya" <zheny list.ru> writes:
```On Friday, 28 December 2012 at 20:19:49 UTC, Simen Kjaeraas wrote:
On 2012-42-28 16:12, Zhenya <zheny list.ru> 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

Thank you,understood)
It's a nice way.
```
Dec 28 2012