MathClassify

Determina il tipo di un numero reale e restituisce un risultato come valore dall'enumerazione ENUM_FP_CLASS.

ENUM_FP_CLASS  MathClassify(
   double  value      // numero reale
   );

Parametri

value

[in] Numero reale da controllare

Valore Restituito

Un valore dall'enumerazione ENUM_FP_CLASS

ENUM_FP_CLASS

ID

Descrizione

FP_SUBNORMAL

Numero subnormale più vicino a zero del più piccolo numero normale rappresentabile DBL_MIN (2.2250738585072014e-308)

FP_NORMAL

Un numero normale nell'intervallo tra 2.2250738585072014e-308 e 1.7976931348623158e+308

FP_ZERO

Uno zero positivo o negativo

FP_INFINITE

Un numero che non può essere rappresentato dal tipo appropriato, infinito positivo o negativo

FP_NAN

Non un numero.

Esempio:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
//--- test NaN
  double nan=double("nan");
  PrintFormat("Test NaN: %G is %s, MathIsValidNumber(NaN)=%s",
              nan,
              EnumToString(MathClassify(nan)),
              (string)MathIsValidNumber(nan));
//--- test infinito
  double inf=double("inf");
  PrintFormat("Test Inf: %G is %s, MathIsValidNumber(inf)=%s",
              inf,
              EnumToString(MathClassify(inf)),
              (string)MathIsValidNumber(inf));
//--- test valore normale
  double normal=1.2345e6;
  PrintFormat("Test Normal: %G is %s, MathIsValidNumber(normal)=%s",
              normal,
              EnumToString(MathClassify(normal)),
              (string)MathIsValidNumber(normal));
//--- test valore subnormale
  double sub_normal=DBL_MIN/2.0;
  PrintFormat("Test Subnormal: %G is %s, MathIsValidNumber(sub_normal)=%s",
              sub_normal,
              EnumToString(MathClassify(sub_normal)),
              (string)MathIsValidNumber(sub_normal));
//--- test valore zero
  double zero=0.0/(-1);
  PrintFormat("Test Zero: %G is %s, MathIsValidNumber(zero)=%s",
              zero,
              EnumToString(MathClassify(zero)),
              (string)MathIsValidNumber(zero));
 } 
 /*
Risultato:
   Test NaNNAN is FP_NANMathIsValidNumber(NaN)=false
   Test InfINF is FP_INFINITEMathIsValidNumber(inf)=false
   Test Normal1.2345E+06 is FP_NORMALMathIsValidNumber(normal)=true
   Test Subnormal1.11254E-308 is FP_SUBNORMALMathIsValidNumber(sub_normal)=true
   Test Zero: -0 is FP_ZEROMathIsValidNumber(zero)=true
*/ 
//+------------------------------------------------------------------+

Vedere anche

Tipi reali (double, float), MathIsValidNumber