Post Reply 
Detecting an emulator's number representation
11-18-2019, 10:51 AM
Post: #1
Detecting an emulator's number representation
Aside from the question of how many bits or bytes are used, an emulator can either use binary or decimal internally. I'm thinking the kinds of inaccuracies of the two systems will differ, so there might be some simple calculation which shows whether binary or decimal is in use.

For example, and where I first noticed this, 800/81 has a pleasing form on a decimal machine such as the 15C:
800 ENTER 81 /
9.876543210

Whereas a workalike emulator which uses (binary) floats internally returns
9.876543209

I see the same two results respectively on an HP35 microcode emulator and an HP35 workalike emulator.

However, I can imagine a mere difference in precision or in rounding tactics might also show this difference: with a few more digits we see the more precise result 9.87654320988 and indeed the mathematic result is a repeating fraction: 9.87654320987654320...

Any ideas for simple calculations which might expose the difference?
Find all posts by this user
Quote this message in a reply
11-18-2019, 11:04 AM
Post: #2
RE: Detecting an emulator's number representation
You need to try and force a calculation to return a number that can be represented exactly only in decimal, not in binary. Try \(\frac{1}{10^n}\) for various positive integer values of n.

Conversely, there are values that can only be represented exactly in binary, not in decimal with a fixed number of digits available, such as \(\frac{1}{2^n}\).

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
11-18-2019, 04:54 PM
Post: #3
RE: Detecting an emulator's number representation
A simple test: evaluate (1 + 1E-8) - 1 , it returns *exactly* 1E-8 on a decimal machine, and *approximatively* 1E-8 on a binary machine.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
11-18-2019, 06:14 PM (This post was last modified: 11-18-2019 06:14 PM by toml_12953.)
Post: #4
RE: Detecting an emulator's number representation
(11-18-2019 10:51 AM)EdS2 Wrote:  Aside from the question of how many bits or bytes are used, an emulator can either use binary or decimal internally. I'm thinking the kinds of inaccuracies of the two systems will differ, so there might be some simple calculation which shows whether binary or decimal is in use.

Here's an ANSI BASIC program by Peter Norton from the March 10, 1987 issue of PC Magazine. It should be easy to convert to any other language such as HPPL on Prime.

Code:
! A BASIC program to investigate floating point
!
! DEFSNG or DEFDBL ' in MS-compatible BASICs
LET A=2.0
LET B=2.0
LET ONE=1.0
LET TWO=2.0
DO
   IF ((A + ONE) - A) <> ONE THEN EXIT DO
   LET A = TWO * A
LOOP
DO
   IF (A + B) <> A THEN EXIT DO
   LET B = TWO * B
LOOP
LET AA = (A + B) - A
LET THE_BASE=INT(AA)
LET AA = THE_BASE - 1
IF (A + AA) = A THEN LET ROUNDING = 0 ELSE LET ROUNDING = 1
LET DIGITS = 0
LET A = ONE
LET AA = THE_BASE
DO
   LET DIGITS = DIGITS + 1
   LET A = A * AA
LOOP UNTIL ((A + ONE) - A) <> ONE

PRINT THE_BASE;"is the number base"
PRINT DIGITS;"digits of precision"
PRINT "Rounding is ";
IF ROUNDING=0 THEN PRINT "NOT ";
PRINT"done."
END

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
11-19-2019, 09:02 AM
Post: #5
RE: Detecting an emulator's number representation
Thanks for the ideas and suggestions!

(11-18-2019 04:54 PM)J-F Garnier Wrote:  A simple test: evaluate (1 + 1E-8) - 1 , it returns *exactly* 1E-8 on a decimal machine, and *approximatively* 1E-8 on a binary machine.
That's great! Simple, and easy to modify.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)