MQL4 Real Types (double, float)
Overview
Real types (floating-point) represent numbers with fractional parts. MQL4 provides two such types:
float**: 4 bytes, minimal positive value 1.175494351e-38, maximum value 3.402823466e+38. C++ analog: float.double**: 8 bytes, minimal positive value 2.2250738585072014e-308, maximum value 1.7976931348623158e+308. C++ analog: double.double offers twice the precision of float and is generally more convenient. float is useful for memory saving in large arrays.
Representation
12.111, -956.1007, 0.0001, 16).e to denote powers of 10 (e.g., 1.12123515e-25).Precision and Comparison Issues
==) of real numbers is unreliable and should be avoided.**Comparing Real Numbers
Two methods are recommended for comparing real numbers:
1. **Epsilon Comparison**: Compare the absolute difference between two numbers against a small tolerance value (epsilon).
* DBL_EPSILON (for double): 2.2204460492503131e-016. Condition: 1.0 + DBL_EPSILON != 1.0.
* FLT_EPSILON (for float): 1.192092896e-07. Condition: 1.0 + FLT_EPSILON != 1.0.
* Example function: EqualDoubles(d1, d2, epsilon).
2. **Normalized Difference Comparison**: Compare the result of NormalizeDouble(number1 - number2, precision) with zero.
* Example function: CompareDoubles(number1, number2).
Invalid Real Numbers
Mathematical operations can result in invalid numbers:
-1.#IND, -1.#QNAN, 1.#SNAN, 1.#QNAN.1.#INF) and Negative (-1.#INF).MathIsValidNumber() to check if a number is valid.Constants and Related Functions
DBL_EPSILON, FLT_EPSILONDoubleToString()NormalizeDouble()MathIsValidNumber()MathArcsin() (example of function producing invalid numbers)