Page 1 of 2
Strange integer behaviour
Posted: Sun Mar 17, 2024 10:17 pm
by my216
It's been 40 years since I last wrote any code for the ZX81 and I've forgotten any idiosyncrasies it may have had.
If I assign a number to a variable that is greater than 8 digits and then retrieve it with Print it is returned rounded.For example:
LET A = 123456789
PRINT A
1234567900
Also, if I convert A to a string it becomes "1234567900".
Can anyone remind me what is happening here? Thanks.
Re: Strange integer behaviour
Posted: Mon Mar 18, 2024 12:17 am
by stroebeljc
The ZX81 is only capable of precision to 8 digits. Thus, the rounding.
Re: Strange integer behaviour
Posted: Mon Mar 18, 2024 11:30 am
by Moggy
Internally accurate to 9 - 10 digits with 8 displayed after rounding.
Re: Strange integer behaviour
Posted: Mon Mar 18, 2024 1:36 pm
by stroebeljc
Internally accurate down to 1/(2^32) ~= 0.0000000002328306437. So, yes, 9 to 10 digits. 32/log2(10)=9.63, to be more precise.
Re: Strange integer behaviour
Posted: Mon Mar 18, 2024 2:17 pm
by my216
But it's not just printing. As converting the stored value to a string will also give the rounded to 8 digits number.
Re: Strange integer behaviour
Posted: Mon Mar 18, 2024 2:53 pm
by stroebeljc
Sort of like the calculators of the day.
Re: Strange integer behaviour
Posted: Tue Mar 19, 2024 2:42 pm
by zx81jens
Hello Users.
This is shown on Page 28:
https://www.historybit.it/wp-content/up ... amming.pdf
Greetings
Jens
Re: Strange integer behaviour
Posted: Tue Mar 19, 2024 3:14 pm
by my216
yep, but what it doesn't say is that although all digits of 4294967295 are apparently stored, if you do STR$ A (assuming the number is in A) you do not get "4294967295" but "4294967300"
Re: Strange integer behaviour
Posted: Tue Mar 19, 2024 4:28 pm
by 1024MAK
The internal ROM function that converts a floating point number to a string is almost certainly the same routine that converts it for printing to the screen.
Mark
Re: Strange integer behaviour
Posted: Tue Mar 19, 2024 4:59 pm
by Paul
1024MAK wrote: ↑Tue Mar 19, 2024 4:28 pm
The internal ROM function that converts a floating point number to a string is almost certainly the same routine that converts it for printing to the screen.
Mark
You can delete the "almost"