MathClassify
MathClassify
确定实数型,并以ENUM_FP_CLASS枚举值的形式返回结果
ENUM_FP_CLASS MathClassify(
double value // 实数
);参数
- 值
[in] 要被检查的实数
返回值
来自ENUM_FP_CLASS枚举的值
ENUM_FP_CLASS
| ID | 描述 |
|---|---|
| FP_SUBNORMAL | 比最小可表示正规数DBL_MIN (2.2250738585072014e-308)更接近于零的次正规数 |
| FP_NORMAL | 正规数的范围在2.2250738585072014e-308与1.7976931348623158e+308之间 |
| FP_ZERO | 正零或负零 |
| FP_INFINITE | 无法用适当的类型(正或负无穷大)表示的数字 |
| FP_NAN | 非数字。 |
例如:
//+------------------------------------------------------------------+
//| 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 infinity
double inf=double("inf");
PrintFormat("Test Inf: %G is %s, MathIsValidNumber(inf)=%s",
inf,
EnumToString(MathClassify(inf)),
(string)MathIsValidNumber(inf));
//--- test normal value
double normal=1.2345e6;
PrintFormat("Test Normal: %G is %s, MathIsValidNumber(normal)=%s",
normal,
EnumToString(MathClassify(normal)),
(string)MathIsValidNumber(normal));
//--- test subnormal value
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 zero value
double zero=0.0/(-1);
PrintFormat("Test Zero: %G is %s, MathIsValidNumber(zero)=%s",
zero,
EnumToString(MathClassify(zero)),
(string)MathIsValidNumber(zero));
}
/*
Result:
Test NaN: NAN is FP_NAN, MathIsValidNumber(NaN)=false
Test Inf: INF is FP_INFINITE, MathIsValidNumber(inf)=false
Test Normal: 1.2345E+06 is FP_NORMAL, MathIsValidNumber(normal)=true
Test Subnormal: 1.11254E-308 is FP_SUBNORMAL, MathIsValidNumber(sub_normal)=true
Test Zero: -0 is FP_ZERO, MathIsValidNumber(zero)=true
*/
//+------------------------------------------------------------------+