# is it posible to assign NaN to a variable of type double?

Sell products right in MetaTrader. Millions of traders are waiting for this!
70
2012.07.20 18:23

A variable of type double is alway set. Can I assign it to NaN? - MathIsValidNumber() returning false?

```void OnStart()
{
double a;
Print(MathIsValidNumber(a)," ",a); //-> "true 0.0"
}```

doc Quote from: https://www.mql5.com/en/docs/basis/types/double

"Besides the minus infinity there is the plus infinity and NaN (not a number). To determine that this number is invalid, you can use MathIsValidNumber(). According to the IEEE standard, they have a special machine representation. For example, plus infinity for the double type has the bit representation of 0x7FF0 0000 0000 0000."

```void OnStart()
{
double a = 0x7FF0000000000000; // Compilation Warning: "truncation of constant value"
Print(MathIsValidNumber(a)," ",a); //-> "true 9.218868437227405e+018"
}```

Beside the Compilation Warning: "truncation of constant value", the number is still valid!

Is the a way to assign an invalid value?

Documentation on MQL5: Language Basics / Data Types / Real Types (double, float)
• www.mql5.com
Language Basics / Data Types / Real Types (double, float) - Documentation on MQL5
1160
2012.07.21 08:49

It looks like the helpfile explains that pretty clearly:

https://www.mql5.com/en/docs/math/MathIsValidNumber

Documentation on MQL5: Math Functions / MathIsValidNumber
• www.mql5.com
Math Functions / MathIsValidNumber - Documentation on MQL5
70
2012.07.21 09:58

Yes it does it a bit:
"If the checked value is a plus or minus infinity, or "not a number" (NaN), the function returns false."

But how do assign:

1. minus infinity
2. plus infinity
3. NaN

to a double?

These 5 functions MathArcsin, MathLog10, MathArccos, MathSqrt and MathLog are able to return some of theme.