Math error in simple FOR loop with decimal 0.01

Get technical support from the community & developers with specific X16 programs if you can't find the solution elsewhere
(for general non-support related chat about programs please comment directly under the program in the software library)
kelli217
Posts: 531
Joined: Sun Jul 05, 2020 11:27 pm

Re: Math error in simple FOR loop with decimal 0.01

Post by kelli217 »

BTW, here's a fun one:

10 FOR X=10 TO 0 STEP -0.1:NEXT X:PRINT X
BruceRMcF
Posts: 224
Joined: Sat Jan 07, 2023 10:33 pm

Re: Math error in simple FOR loop with decimal 0.01

Post by BruceRMcF »

TomXP411 wrote: Thu Mar 16, 2023 7:19 pm ... (As was pointed out above, the Commodore packed format has a 31-bit mantissa. But this doesn't change the nature of irrational numbers, it just makes them longer.) ...
Quite. It takes more iterations to hit the same imprecision as with 32bit floats, but it will still get there, since there will always be a rounding error at the last bit.
EbonHawk
Posts: 17
Joined: Thu Mar 16, 2023 10:37 am

Re: Math error in simple FOR loop with decimal 0.01

Post by EbonHawk »

Ran the same 3 sets in C64 BASIC (VICE emulator) and the first program hits the same exact issue at the same number (23rd), but doesn't hit the rounding problem till the 79th iteration with the 2nd setup.

Just weird.

But anyway, glad to know it's at least known.
Post Reply