Post Reply 
Detecting an emulator's number representation
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
Post Reply 


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



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