5 PRINT "PROGRAM FILE 27: ACCURACY OF CONSTANTS AND VARIABLES."
10 PRINT "    ANSI STANDARD 5.2, 5.4, 6.2, 6.4, 10.4"
15 PRINT
20 PRINT "*** NOTE: THIS PROGRAM MAKES USE OF THE ON-GOTO STATEMENT"
25 PRINT "    AND FOR-BLOCKS (THE FOR AND NEXT STATEMENTS) WHICH"
30 PRINT "    HAVE NOT YET BEEN TESTED. IF SUBSEQUENT TESTS SHOW"
35 PRINT "    THESE FEATURES TO BE INCORRECTLY IMPLEMENTED, THEN THE"
40 PRINT "    VALIDITY OF THE RESULTS OF THIS TEST ROUTINE IS DOUBTFUL."
45 PRINT
50 PRINT "THIS PROGRAM TESTS THE LEVEL OF ACCURACY OF NUMERIC VALUE,"
55 PRINT "USING THE IF-THEN STATEMENT."
60 LET T1=34
70 LET T2=50
80 LET T3=T1+2
90 LET T4=T2+2
100 PRINT
110 PRINT "SECTION 27.1: ACCURACY IN COMPARISON OF VARIABLES."
120 PRINT
130 PRINT "THIS SECTION COMPARES TWO VARIABLES WHICH HAVE BEEN ASSIGNED"
140 PRINT "NUMERICALLY 'CLOSE' VALUES AND THEN DETERMINES WHETHER THE"
150 PRINT "IMPLEMENTATION CAN DISTINGUISH BETWEEN THEN OR IF THEY ARE"
160 PRINT "TREATED AS EQUAL."
170 PRINT
180 LET C$="  >   ="
190 GOSUB 8000
200 LET A = 9.876543212E-7
210 LET A$="9.876543212E-7 : "
220 FOR I=6 TO 9
230 PRINT A$;
240 LET J=I-5
250 ON J GOTO 600,700,800,900
600 LET B= 9.876533E-7
610 PRINT "9.876533E-7";
620 GOTO 1000
700 LET B= 9.8765422E-7
710 PRINT "9.8765422E-7";
720 GOTO 1000
800 LET B= 9.87654311E-7
810 PRINT "9.87654311E-7";
820 GOTO 1000
900 LET B= 9.876543201E-7
910 PRINT "9.876543201E-7";
920 GOTO 1000
1000 LET U$="T"
1010 LET E$="T"
1020 IF A > B THEN 1040
1030 LET U$="F"
1040 IF A = B THEN 1060
1050 LET E$="F"
1060 REM COMPARISONS FINISHED
1200 GOSUB 8160
1210 NEXT I
1220 GOSUB 8280
3000 PRINT "SECTION 27.2: ACCURACY IN THE COMPARISON OF VARIABLES"
3010 PRINT "              WITH CONSTANTS."
3020 PRINT
3030 PRINT "THIS SECTION COMPARES A VARIABLE AND A CONSTANT WHICH HAVE"
3040 PRINT "NUMERICALLY 'CLOSE' VALUES AND THEN DETERMINES WHETHER THE"
3050 PRINT "IMPLEMENTATION CAN DISTINGUISH BETWEEN THEM OR IF THEY ARE"
3060 PRINT "TREATED AS EQUAL."
3070 PRINT
3080 LET C$="  >   ="
3090 GOSUB 8000
3100 LET A$="-9.999988888E36 : "
3110 FOR I=6 TO 9
3120 PRINT A$;
3130 LET J=I-5
3140 ON J GOTO 3200,3300,3400,3500
3200 LET B= -9.999999E36
3210 PRINT "-9.999999E36";
3220 GOTO 3600
3300 LET B= -9.9999899E36
3310 PRINT "-9.9999899E36";
3320 GOTO 3600
3400 LET B= -9.99998899E36
3410 PRINT "-9.99998899E36";
3420 GOTO 3600
3500 LET B= -9.999988899E36
3510 PRINT "-9.999988899E36";
3520 GOTO 3600
3600 LET U$="T"
3610 LET E$="T"
3620 IF -9.999988888E36 > B THEN 3640
3630 LET U$="F"
3640 IF -9.999988888E36 = B THEN 3660
3650 LET E$="F"
3660 REM COMPARISON FINISHED
3670 GOSUB 8160
3680 NEXT I
3690 GOSUB 8280
5000 PRINT "SECTION 27.3: ACCURACY IN THE COMPARISON OF CONSTANTS."
5010 PRINT
5020 PRINT "THIS SECTION COMPARES TWO CONSTANTS WHICH HAVE"
5030 PRINT "NUMERICALLY 'CLOSE' VALUES AND THEN DETERMINES WHETHER THE"
5040 PRINT "IMPLEMENTATION CAN DISTINGUISH BETWEEN THEM OR IF THEY ARE"
5050 PRINT "TREATED AS EQUAL."
5060 PRINT
5070 LET C$="  <   ="
5080 GOSUB 8000
5090 LET A$="9.40395E-37 : "
5100 FOR I=6 TO 9
5110 PRINT A$;
5120 LET U$="T"
5130 LET E$="T"
5140 LET J=I-5
5150 ON J GOTO 5200,5300,5400,5500
5200 IF 9.40395E-37 < 9.40396E-37 THEN 5220
5210 LET U$="F"
5220 IF 9.40395E-37 = 9.40396E-17 THEN 5240
5230 LET E$="F"
5240 PRINT "9.40396E-37";
5250 GOTO 5600
5300 IF 9.40395E-37 < 9.403951E-37 THEN 5320
5310 LET U$="F"
5320 IF 9.40395E-37 = 9.403951E-37 THEN 5340
5330 LET E$="F"
5340 PRINT "9.403951E-37";
5350 GOTO 5600
5400 IF 9.40395E-37 < 9.4039501E-37 THEN 5420
5410 LET U$="F"
5420 IF 9.40395E-37 = 9.4039501E-37 THEN 5440
5430 LET E$="F"
5440 PRINT "9.4039501E-37";
5450 GOTO 5600
5500 IF 9.40395E-37 < 9.40395001E-37 THEN 5520
5510 LET U$="F"
5520 IF 9.40395E-37 = 9.40395001E-37 THEN 5540
5530 LET E$="F"
5540 PRINT "9.40395001E-37";
5550 GOTO 5600
5600 REM COMPARISONS FINISHED
5610 GOSUB 8160
5620 NEXT I
5630 GOSUB 8280
5800 PRINT "SECTION 27.4: ACCURACY FOR CONSTANTS EXPRESSED WITH"
5810 PRINT "        DIFFERENT EXPONENTS."
5820 PRINT
5830 PRINT "CONSTANTS MUST BE ACCURATE EVEN WHEN NOT EXPRESSED IN"
5840 PRINT "NORMALIZED FORM (1 <= SIGNIFICAND < 10)."
5850 PRINT
5860 PRINT "                 BEGIN TEST."
5870 PRINT
5880 IF .0000000999991E-18 >= 99999200000E-36 THEN 5950
5890 IF -.0000000999991E-18 <= -99999200000E-36 THEN 5950
5900 IF .0000000999992E-18 >= 99999300000E-36 THEN 5950
5910 IF -.0000000999992E-18 <= -99999300000E-36 THEN 5950
5920 IF .0000000999993E-18 >= 99999400000E-36 THEN 5950
5930 IF -.0000000999993E-18 <= -99999400000E-36 THEN 5950
5940 PRINT "*** TEST PASSED ***"
5945 GO TO 5955
5950 PRINT "*** TEST FAILED ***"
5955 PRINT
5960 PRINT "                  END TEST."
5970 PRINT
6000 PRINT "SECTION 27.5: COMPUTED ACCURACY OF NUMERIC VALUES."
6010 PRINT
6020 PRINT "THIS SECTION USES A COMPUTATIONAL ALGORITHM TO ATTEMPT TO"
6030 PRINT "DISCOVER THIS IMPLEMENTATION'S INTERNAL ACCURACY. BECAUSE"
6040 PRINT "THE ALGORITHM RELIES SOMEWHAT ON ACCURACY OF EXPRESSION"
6050 PRINT "EVALUATION, THE RESULTS ARE NOT ABSOLUTELY TRUSTWORTHY AND"
6060 PRINT "SHOULD BE INTERPRETED IN LIGHT OF GENERAL KNOWLEDGE OF"
6070 PRINT "THE CHARACTERISTICS OF THE SYSTEM."
6080 PRINT
6090 PRINT "*** THIS TEST IS INFORMATIVE ONLY ***"
6100 PRINT
6110 PRINT "              BEGIN TEST."
6120 PRINT
6130 LET B=10
6140 LET B$="DECIMAL"
6150 GOSUB 6230
6160 LET B=2
6170 LET B$="BINARY"
6180 GOSUB 6230
6190 PRINT
6200 PRINT "               END TEST."
6210 PRINT
6220 GOTO 6430
6230 LET S=1
6240 LET E=S
6250 LET D=-1
6260 LET E=E/B
6270 LET T2 = S - E
6280 LET T1=T2
6290 REM THE NEXT FOUR STATEMENTS HAVE NO ALGORITHMIC PURPOSE -
6300 REM THEY ARE AN ATTEMPT TO FORCE THE VARIABLE T1 TO BE STORED
6310 REM RATHER THAN SAVED IN OVERLENGTH REGISTERS, AS IS DONE
6320 REM BY SOME MACHINES, WITH AN OPTIMIZING COMPILER.
6325 LET V=1
6330 LET U=E+D
6340 LET V=U*D*(-V)
6350 IF V < 0 THEN 6330
6360 LET D=D+1
6370 IF D>500 THEN 6410
6380 IF T1 < S THEN 6260
6390 PRINT "COMPUTED ACCURACY = ";D;B$;" DIGITS."
6400 RETURN
6410 PRINT "UNABLE TO COMPUTE ACCURACY OF ";B$;" DIGITS."
6420 RETURN
6430 REM END SECTION
6440 PRINT "END PROGRAM 27"
6450 STOP
8000 REM SUBROUTINE TO BEGIN SECTION
8010 PRINT "                  BEGIN TEST."
8020 PRINT
8030 PRINT "NUMERIC VALUES";TAB(T1);"DIGITS OF";TAB(T2);
8040 PRINT "RESULT OF"
8050 PRINT "BEING COMPARED";TAB(T1);"DECIMAL";TAB(T2);
8060 PRINT "COMPARISONS"
8070 PRINT TAB(T1);"ACCURACY";TAB(T2);C$
8080 PRINT
8090 REM NO. OF ANOMALOUS RESULTS (BOTH TRUE OR BOTH FALSE)
8100 LET S2=0
8110 REM SIGNIFICANCE SWITCH - 1 IMPLIES LOST SIGNIFICANCE
8120 LET S1=0
8130 REM NO. OF SIGNIFICANT DIGITS
8140 LET S0=5
8150 RETURN
8160 REM SUBROUTINE TO SUMMARIZE LINE
8170 LET W$=" "
8180 IF E$=U$ THEN 8230
8190 IF U$="F" THEN 8250
8200 IF S1=1 THEN 8260
8210 LET S0=I
8220 GOTO 8260
8230 LET W$="***"
8240 LET S2=S2+1
8250 LET S1=1
8260 PRINT TAB(T3);I;TAB(T4);U$;"   ";E$;"   ";W$
8270 RETURN
8280 REM SUBROUTINE TO END SECTION
8290 LET T$="LEAST"
8300 IF S0=9 THEN 8320
8310 LET T$="MOST"
8320 PRINT
8330 PRINT "*** TEST INDICATES DECIMAL ACCURACY OF AT ";T$;" ";S0;
8340 PRINT "DIGITS. ***"
8350 IF S0 < 6 THEN 8400
8360 PRINT "IF DOCUMENTATION FOR THE IMPLEMENTATION-DEFINED ACCURACY"
8370 PRINT "   FOR NUMERIC VALUES IS COMPATIBLE WITH THIS RESULT, THEN"
8380 PRINT "*** TEST PASSED ***"
8390 GOTO 8410
8400 PRINT "*** TEST FAILED: MINIMUM ACCURACY IS SIX DIGITS. ***"
8410 PRINT
8420 IF S2=0 THEN 8460
8430 PRINT "*** NOTE ANOMALOUS COMPARISON RESULTS IN THE ";S2;" ROW(S)"
8440 PRINT "    ABOVE FOLLOWED BY ASTERISKS. ***"
8450 PRINT
8460 PRINT "                   END TEST."
8470 PRINT
8480 RETURN
8490 END
