UsingFloating Point
Be aware of round-off error occurring due to the limited number of bits available for each of the mantissa and exponent.
Make sure you pick a storage type with enough bits for precision and range to accurately represent the numbers you use.
Note that a four-byte integer has more bits of precision than a four-byte floating-point number. A four-byte integer has less range than a four-byte floating point #.
Never compare floating-point numbers for exact equality; test for close enough against a reasonably small value:
- absolute_value(f1 - f2) < epsilon