Is This A Bug In The iOS ZX81 Emulator?

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Is This A Bug In The iOS ZX81 Emulator?

Post by MrVertigo »

Or am I doing something stupid? I can’t for the life of me work out why the second output of this routine is zero. It should be 1.

Code: Select all

10 Let C=24
20 Let X=4
30 Let A=8

40 Let C= C/X
50 Let D= A/C
60 Let F= Int D
70 Let A= (D-F)*C
80 Print F

120 Let C= C/(x-1)
130 Let D=A/C
140 Let F= Int D
150 Print F
Line 150 should return “1”. If you input the results of part one manually (C=6, X=4, A=2) and run the program from line 120, it produces the correct result: line 150 returns “1”. If you print out C, X and A between line 80 and 120, they are 6,4 and 2. If you print A and C after line 130 they are 2 and 2, as they should be. If you print out A and C after line 140 they are 2 and 2. So why on earth is F zero?

Some numbers it works properly. For example if you change the starting conditions to C=24, X=4 and A=9, it works correctly. But starting with C=6, X=2 and A=3 gives the wrong output at 150 too.

Why is this? What am I missing?
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by XavSnap »

int.JPG
INT 0.99999999999999999 = 0
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by 1024MAK »

One thing to remember is that with floating point numbers, what the ZX81 stores/uses is not what us humans see.

When you enter a decimal number, the ZX81 changes this to a floating point binary representation of that number. Hence if you then get it to perform calculations, sometimes rounding can cause unexpected results.

And that’s with the “bug fixed” ROM…

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.
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by MrVertigo »

Ah, thanks for these replies! They make it very clear what is happening.

Is the best solution to use a loop that subtracts C from A the required number of times, rather than dividing? Or is there a better workaround?
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by Moggy »

Concerning how the computer treats its binary representation of numbers, you may find the following links enlightening.

https://archive.org/stream/ZX-computing ... 3/mode/2up

https://archive.org/stream/ZX-computing ... 7/mode/1up

https://archive.org/stream/ZX-computing ... 8/mode/1up
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by MrVertigo »

Thanks for these!
User avatar
1024MAK
Posts: 5118
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by 1024MAK »

If it makes you feel any better/worse (delete as applicable :lol: )...

Floating point rounding errors on a ZX Spectrum 128K using the Qaop emulator:
Floating point rounding errors on a ZX Spectrum 128K
Floating point rounding errors on a ZX Spectrum 128K
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.
MrVertigo
Posts: 106
Joined: Fri May 27, 2022 9:06 pm

Re: Is This A Bug In The iOS ZX81 Emulator?

Post by MrVertigo »

:D
Post Reply