I can´t explain this (math precision)

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

I can´t explain this (math precision)

Post by bola_dor »

I know that roughly the mathematical precision of the ZX81 starts to lose after 9 digits, one would expect rounding and exponential expressions.
What I can't explain is why the same statement "LET a=-0.999999999999999999999999" gives two different results in this case.
I would expect -1 as rounding, or anything else, what puzzles me is that the result is not consistent.
I tried the same listing on Spectrum BASIC and the result is always 2... why not -1 ?
  • 10 LET A=-0.9999999999999999
    20 PRINT -0.9999999999999999
    30 PRINT A
    40 POKE 16436,255
    50 POKE 16437,255
    60 LET SS=PEEK 16436+256*PEEK 16437
    70 FOR F=1 TO 100
    80 LET A=-0.9999999999999999
    90 NEXT F
    100 LET EU=PEEK 16436+256*PEEK 16437
    110 LET E1=ABS SS-EU
    120 PRINT A;":",E1/50;""""
test.jpg
test.jpg (1.43 KiB) Viewed 4599 times
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: I can´t explain this (math precision)

Post by 1024MAK »

Which ROM is your machine using?

Using the last and latest Sinclair official ZX81 ROM I get:
Maths - rounding
Maths - rounding
The above was done on an emulator (the excellent one for iOS) using 16K RAM and the 649 ROM.

I also tried on a emulator for a ZX Spectrum 128, but without the timing parts of the program (so only lines 10 to 30, 70 to 90 and line 120.

This printed -1 three times.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: I can´t explain this (math precision)

Post by bola_dor »

1024MAK wrote: Sun May 21, 2023 12:05 am Which ROM is your machine using?

Using the last and latest Sinclair official ZX81 ROM I get:
IMG_6117.jpeg
The above was done on an emulator (the excellent one for iOS) using 16K RAM and the 649 ROM.

I also tried on a emulator for a ZX Spectrum 128, but without the timing parts of the program (so only lines 10 to 30, 70 to 90 and line 120.

This printed -1 three times.

Mark
i used Eighyone v1.29 zx81.version2.rom
and spec48.rom and spec128.rom

Now I tried zx81.version3.rom and results are al 2...
anyway I woul spect -1
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: I can´t explain this (math precision)

Post by XavSnap »

Hi bola_dor,

Try to edit the line 80 using shifted 1 and press New/Line without changes.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply