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

 

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
 

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
 

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.
Your answer imply using theme and no constant or something else.

The wired thing is that EMPTY_VALUE is a Valid Number.

Thank you, I'll go for MathSqrt(-1) 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Named Constants / Other Constants - Documentation on MQL5
 
dck #:

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? 

#define  NaN DBL_MAX*2
 
void OnStart()
  {
   double foo = double("nan");
   Print(foo);
  }

Special double values:

double foo = double("nan");
double foo = double("inf");
double foo = double("-inf");

Example

if(condition)
   return result;
else
   return double("nan");