Strange integer behaviour
Strange integer behaviour
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.
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.
-
- Posts: 74
- Joined: Thu Apr 23, 2020 6:02 am
Re: Strange integer behaviour
The ZX81 is only capable of precision to 8 digits. Thus, the rounding.
John
Re: Strange integer behaviour
Internally accurate to 9 - 10 digits with 8 displayed after rounding.
-
- Posts: 74
- Joined: Thu Apr 23, 2020 6:02 am
Re: Strange integer behaviour
Internally accurate down to 1/(2^32) ~= 0.0000000002328306437. So, yes, 9 to 10 digits. 32/log2(10)=9.63, to be more precise.
Last edited by stroebeljc on Mon Mar 18, 2024 2:49 pm, edited 1 time in total.
John
Re: Strange integer behaviour
But it's not just printing. As converting the stored value to a string will also give the rounded to 8 digits number.
-
- Posts: 74
- Joined: Thu Apr 23, 2020 6:02 am
Re: Strange integer behaviour
Hello Users.
This is shown on Page 28:
https://www.historybit.it/wp-content/up ... amming.pdf
Greetings
Jens
This is shown on Page 28:
https://www.historybit.it/wp-content/up ... amming.pdf
Greetings
Jens
eyerything will be okay in the end.
if it´s not okay, it´s not the end.
and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı
if it´s not okay, it´s not the end.
and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı
Re: Strange integer behaviour
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"
- 1024MAK
- Posts: 5332
- Joined: Mon Sep 26, 2011 10:56 am
- Location: Looking forward to summer in Somerset, UK...
Re: Strange integer behaviour
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
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp
Standby alert
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Autumn is here. Bye bye summer 2024...
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp
Standby alert
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Autumn is here. Bye bye summer 2024...
Re: Strange integer behaviour
You can delete the "almost"
In theory, there is no difference between theory and practice. But, in practice, there is.