Floating point nuisance

Blitz3D Forums/Blitz3D Programming/Floating point nuisance

If you are using WriteFloat and ReadFloat then numbers read back exactly as written.

The displayed value 1.56462e-006 means 1.56462 with the decimal point moved six places to the left. So .00000156462 is the actual value. This is essentially zero.

I have no idea how any of this relates to the supposed value X = 4.0.

The LimitFloat# problem is another matter. Try this simple program.
x# = 189.98
Print x

This happens because older versions of Blitz try to display too many digits.
Newer versions will display 189.98, as expected.

But in fact there is no such number in floating point.
Decimal numbers are approximated in base two using an integer divided by some power of two.

189.98 is approximated by 12450529 / 65536, which is actually 189.9799957275...

When rounded to six digits this displays as 189.98.
Older versions show six digits after the decimal point, which gives 189.979996.
And neither is the exact value being used internally.

It's a fact of life. Floating point is approximate.