5 ms·
According to something I read somewhere. The ZX81 floating routines did incorperate some unique math: (2^32) - ((2^32)-1) did not return 1 And the group of Ca
by trynton 6y ago
According to something I read somewhere. The ZX81 floating routines did incorperate some unique math:
(2^32) - ((2^32)-1) did not return 1
And the group of Cambridge mathamaticians that wrote the ROM turned out to be one man.
"ZX81 ROM Assembly Listing"
https://www.tablix.org/~avian/spectrum/rom/zx81.htm https://www.tablix.org/~avian/spectrum/rom/zx81.htm
- rwmj 6y agoI just tried it on the ZX81 online emulator: http://www.zx81stuff.org.uk/zx81/jtyone.html http://www.zx81stuff.org.uk/zx81/jtyone.html You have to type the following sequence of keys: P [Shift]I 2 [Shift]H 3 2 [Shift]O - [Shift]I [Shift]I 2 [Shift]H 3 2 [Shift]O - 1 [Shift]O Enter which should appear as: PRINT (2**32)-((2**32)-1) It prints 0 which is not the expected answer! (The 0/0 at the bottom of the screeen is an OK message, the answer is printed in the top left corner). I think this isn't necessarily a bug, it's because the computer used something similar to modern single precision floating point. Also try this (SQR is entered as: [Shift]Enter H): PRINT SQR 0.25 On the emulator it looks like the bug has been fixed, but on early models of the real hardware it would give a completely bogus result. I think what was interesting was it used a kind of bytecode to run maths routines (similar to the Apple II's SWEET16 code).
- zokier 6y ago0 is actually what I'd expect as an answer. Even on very modern Python you get In [1]: 2.0**64 - (2.0**64-1.0) Out[1]: 0.0 Thats how floats behave like with operands that differ greatly in magnitude. Also this In [2]: 2.0**64 == (2.0**64 - 1.0) Out[2]: True
- trynton 6y ago> 0 is actually what I'd expect as an answer. Even on very modern Python you get Given a four byte mantissa, it should be 1 for anything under and equal to 2^32 and 0 for anything over 2^32. Instead it outputted some random number. A bug in checking the flags or some-such. Or maybe a bug in the float to string routine.
- zokier 6y agoThe sign takes one bit off the mantissa.
- anthk 6y ago"1" in Scheme: >(- (expt 2 64) (- (expt 2 64) 1)) 1 http://people.csail.mit.edu/jaffer/SCM.html http://people.csail.mit.edu/jaffer/SCM.html
- jhbadger 6y agoAre you sure that isn't just doing integer math? I don't have a scheme implementation handy, but I tried it in sbcl Common Lisp and while (- (expt 2 64) (- (expt 2 64) 1)) does yield 1, (- (expt 2.0 64) (- (expt 2.0 64) 1)) yields 0.
- anthk 6y agoTrue, 0. But I think Guile had an exact->inexact function.
- trynton 6y agoAccording to the link to ""ZX81 ROM Assembly Listing"", it used a "FORTH-like, stack-based language.". Amazing all the same how they managed to squeeze so much out of so little.