HP Forums
Detecting an emulator's number representation - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not quite HP Calculators - but related (/forum-8.html)
+--- Thread: Detecting an emulator's number representation (/thread-14006.html)



Detecting an emulator's number representation - EdS2 - 11-18-2019 10:51 AM

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?


RE: Detecting an emulator's number representation - grsbanks - 11-18-2019 11:04 AM

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}\).


RE: Detecting an emulator's number representation - J-F Garnier - 11-18-2019 04:54 PM

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


RE: Detecting an emulator's number representation - toml_12953 - 11-18-2019 06:14 PM

(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



RE: Detecting an emulator's number representation - EdS2 - 11-19-2019 09:02 AM

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.