Data Type Troubleshooting
What follows is a list of problems that can occur when you use intrinsic data types.
Floating-point values do not compare as equal
When you use floating-point numbers (Real32
, Real64
, and Real128
), know that they are stored as binary fractions.
They can hold an accurate quantity only when it is a binary fraction with k / (2 ^ n)
, where k
and n
are integers.
For example, 0.5 = 1/2
and 0.1875 = 3/16
.
Thus these are accurate values.
But 0.3 = 3/10
and 0.15 = 3/20
, thus these are approximate values.
Because of this, you cannot be sure of accurate values as a result of floating-point operations. Thus you must not think that two given values will be equal only because mathematics tells you that they are.
To compare floating-point values, follow these steps:
- Select a satisfactory maximum tolerance for the given comparison. All values in this range will become equal.
- Put
Tol
directly after the end of the comparison expression. - Follow that with the selected tolerance value.
This can be a floating-point literal or a declared constant (See
Const
).
See Tol Clause for more information.
Boolean to numeric type conversion causes problems
TODO