80386 alternative math library part03/04

Glenn Geers glenn at extro.ucc.su.OZ.AU
Sat Dec 8 08:58:49 AEST 1990


Submitted-by: glenn at trantor
Archive-name: libfpu/part03

#!/bin/sh
# This is part 03 of libfpu
# ============= paranoia.c ==============
if test -f 'paranoia.c' -a X"$1" != X"-c"; then
	echo 'x - skipping paranoia.c (File already exists)'
else
echo 'x - extracting paranoia.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'paranoia.c' &&
/*	A C version of Kahan's Floating Point Test "Paranoia"
X
X			Thos Sumner, UCSF, Feb. 1985
X			David Gay, BTL, Jan. 1986
X
X	This is a rewrite from the Pascal version by
X
X			B. A. Wichmann, 18 Jan. 1985
X
X	(and does NOT exhibit good C programming style).
X
(C) Apr 19 1983 in BASIC version by:
X	Professor W. M. Kahan,
X	567 Evans Hall
X	Electrical Engineering & Computer Science Dept.
X	University of California
X	Berkeley, California 94720
X	USA
X
converted to Pascal by:
X	B. A. Wichmann
X	National Physical Laboratory
X	Teddington Middx
X	TW11 OLW
X	UK
X
converted to C by:
X
X	David M. Gay		and	Thos Sumner
X	AT&T Bell Labs			Computer Center, Rm. U-76
X	600 Mountain Avenue		University of California
X	Murray Hill, NJ 07974		San Francisco, CA 94143
X	USA				USA
X
with simultaneous corrections to the Pascal source (reflected
in the Pascal source available over netlib).
[A couple of bug fixes from dgh = sun!dhough incorporated 31 July 1986.]
X
Reports of results on various systems from all the versions
of Paranoia are being collected by Richard Karpinski at the
same address as Thos Sumner.  This includes sample outputs,
bug reports, and criticisms.
X
You may copy this program freely if you acknowledge its source.
Comments on the Pascal version to NPL, please.
X
X
The C version catches signals from floating-point exceptions.
If signal(SIGFPE,...) is unavailable in your environment, you may
#define NOSIGNAL to comment out the invocations of signal.
X
This source file is too big for some C compilers, but may be split
into pieces.  Comments containing "SPLIT" suggest convenient places
for this splitting.  At the end of these comments is an "ed script"
(for the UNIX(tm) editor ed) that will do this splitting.
X
By #defining Single when you compile this source, you may obtain
a single-precision C version of Paranoia.
X
X
The following is from the introductory commentary from Wichmann's work:
X
The BASIC program of Kahan is written in Microsoft BASIC using many
facilities which have no exact analogy in Pascal.  The Pascal
version below cannot therefore be exactly the same.  Rather than be
a minimal transcription of the BASIC program, the Pascal coding
follows the conventional style of block-structured languages.  Hence
the Pascal version could be useful in producing versions in other
structured languages.
X
Rather than use identifiers of minimal length (which therefore have
little mnemonic significance), the Pascal version uses meaningful
identifiers as follows [Note: A few changes have been made for C]:
X
X
BASIC   C               BASIC   C               BASIC   C               
X
X   A                       J                       S    StickyBit
X   A1   AInverse           J0   NoErrors           T
X   B    Radix                    [Failure]         T0   Underflow
X   B1   BInverse           J1   NoErrors           T2   ThirtyTwo
X   B2   RadixD2                  [SeriousDefect]   T5   OneAndHalf
X   B9   BMinusU2           J2   NoErrors           T7   TwentySeven
X   C                             [Defect]          T8   TwoForty
X   C1   CInverse           J3   NoErrors           U    OneUlp
X   D                             [Flaw]            U0   UnderflowThreshold
X   D4   FourD              K    PageNo             U1
X   E0                      L    Milestone          U2
X   E1                      M                       V
X   E2   Exp2               N                       V0
X   E3                      N1                      V8
X   E5   MinSqEr            O    Zero               V9
X   E6   SqEr               O1   One                W
X   E7   MaxSqEr            O2   Two                X
X   E8                      O3   Three              X1
X   E9                      O4   Four               X8
X   F1   MinusOne           O5   Five               X9   Random1
X   F2   Half               O8   Eight              Y
X   F3   Third              O9   Nine               Y1
X   F6                      P    Precision          Y2
X   F9                      Q                       Y9   Random2
X   G1   GMult              Q8                      Z
X   G2   GDiv               Q9                      Z0   PseudoZero
X   G3   GAddSub            R                       Z1
X   H                       R1   RMult              Z2
X   H1   HInverse           R2   RDiv               Z9
X   I                       R3   RAddSub
X   IO   NoTrials           R4   RSqrt
X   I3   IEEE               R9   Random9
X
X   SqRWrng
X
All the variables in BASIC are true variables and in consequence,
the program is more difficult to follow since the "constants" must
be determined (the glossary is very helpful).  The Pascal version
uses Real constants, but checks are added to ensure that the values
are correctly converted by the compiler.
X
The major textual change to the Pascal version apart from the
identifiersis that named procedures are used, inserting parameters
wherehelpful.  New procedures are also introduced.  The
correspondence is as follows:
X
X
BASIC       Pascal
lines 
X
X  90- 140   Pause
X 170- 250   Instructions
X 380- 460   Heading
X 480- 670   Characteristics
X 690- 870   History
2940-2950   Random
3710-3740   NewD
4040-4080   DoesYequalX
4090-4110   PrintIfNPositive
4640-4850   TestPartialUnderflow
X
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
X
Below is an "ed script" that splits para.c into 10 files
of the form part[1-8].c, subs.c, and msgs.c, plus a header
file, paranoia.h, that these files require.
X
r paranoia.c
$
?SPLIT
+,$w msgs.c
X .,$d
?SPLIT
X .d
+d
-,$w subs.c
-,$d
?part8
+d
?include
X .,$w part8.c
X .,$d
-d
?part7
+d
?include
X .,$w part7.c
X .,$d
-d
?part6
+d
?include
X .,$w part6.c
X .,$d
-d
?part5
+d
?include
X .,$w part5.c
X .,$d
-d
?part4
+d
?include
X .,$w part4.c
X .,$d
-d
?part3
+d
?include
X .,$w part3.c
X .,$d
-d
?part2
+d
?include
X .,$w part2.c
X .,$d
?SPLIT
X .d
1,/^#include/-1d
1,$w part1.c
/Computed constants/,$d
1,$s/^int/extern &/
1,$s/^FLOAT/extern &/
1,$s/^char/extern &/
1,$s! = .*!;!
/^Guard/,/^Round/s/^/extern /
/^jmp_buf/s/^/extern /
/^Sig_type/s/^/extern /
s/$/\
extern void sigfpe();/
w paranoia.h
q
X
*/
X
#include <stdio.h>
#ifndef NOSIGNAL
#include <signal.h>
#endif
#include <setjmp.h>
X
extern double fabs(), floor(), log(), pow();
#ifdef TEST
extern double sqrtp();
#else
extern double sqrt();
#endif
X
#ifdef Single
#define FLOAT float
#define FABS(x) (float)fabs((double)(x))
#define FLOOR(x) (float)floor((double)(x))
#define LOG(x) (float)log((double)(x))
#define POW(x,y) (float)pow((double)(x),(double)(y))
#ifdef TEST
#define SQRT(x) (float)sqrtp((double)(x))
#else
#define SQRT(x) (float)sqrt((double)(x))
#endif
#else
#define FLOAT double
#define FABS(x) fabs(x)
#define FLOOR(x) floor(x)
#define LOG(x) log(x)
#define POW(x,y) pow(x,y)
#ifdef TEST
#define SQRT(x) sqrtp(x)
#else
#define SQRT(x) sqrt(x)
#endif
#endif
X
jmp_buf ovfl_buf;
typedef void (*Sig_type)();
Sig_type sigsave;
X
#define KEYBOARD 0
X
FLOAT Radix, BInvrse, RadixD2, BMinusU2;
FLOAT Sign(), Random();
X
/*Small floating point constants.*/
FLOAT Zero = 0.0;
FLOAT Half = 0.5;
FLOAT One = 1.0;
FLOAT Two = 2.0;
FLOAT Three = 3.0;
FLOAT Four = 4.0;
FLOAT Five = 5.0;
FLOAT Eight = 8.0;
FLOAT Nine = 9.0;
FLOAT TwentySeven = 27.0;
FLOAT ThirtyTwo = 32.0;
FLOAT TwoForty = 240.0;
FLOAT MinusOne = -1.0;
FLOAT OneAndHalf = 1.5;
/*Integer constants*/
int NoTrials = 20; /*Number of tests for commutativity. */
#define False 0
#define True 1
X
/* Definitions for declared types 
X	Guard == (Yes, No);
X	Rounding == (Chopped, Rounded, Other);
X	Message == packed array [1..40] of char;
X	Class == (Flaw, Defect, Serious, Failure);
X	  */
#define Yes 1
#define No  0
#define Chopped 2
#define Rounded 1
#define Other   0
#define Flaw    3
#define Defect  2
#define Serious 1
#define Failure 0
typedef int Guard, Rounding, Class;
typedef char Message;
X
/* Declarations of Variables */
int Indx;
char ch[8];
FLOAT AInvrse, A1;
FLOAT C, CInvrse;
FLOAT D, FourD;
FLOAT E0, E1, Exp2, E3, MinSqEr;
FLOAT SqEr, MaxSqEr, E9;
FLOAT Third;
FLOAT F6, F9;
FLOAT H, HInvrse;
int I;
FLOAT StickyBit, J;
FLOAT MyZero;
FLOAT Precision;
FLOAT Q, Q9;
FLOAT R, Random9;
FLOAT T, Underflow, S;
FLOAT OneUlp, UfThold, U1, U2;
FLOAT V, V0, V9;
FLOAT W;
FLOAT X, X1, X2, X8, Random1;
FLOAT Y, Y1, Y2, Random2;
FLOAT Z, PseudoZero, Z1, Z2, Z9;
int ErrCnt[4];
int fpecount;
int Milestone;
int PageNo;
int M, N, N1;
Guard GMult, GDiv, GAddSub;
Rounding RMult, RDiv, RAddSub, RSqrt;
int Break, Done, NotMonot, Monot, Anomaly, IEEE,
X		SqRWrng, UfNGrad;
/* Computed constants. */
/*U1  gap below 1.0, i.e, 1.0-U1 is next number below 1.0 */
/*U2  gap above 1.0, i.e, 1.0+U2 is next number above 1.0 */
X
/* floating point exception receiver */
X void
sigfpe()
{
X	fpecount++;
X	printf("\n* * * FLOATING-POINT ERROR * * *\n");
X	fflush(stdout);
X	if (sigsave) {
#ifndef NOSIGNAL
X		signal(SIGFPE, sigsave);
#endif
X		sigsave = 0;
X		longjmp(ovfl_buf, 1);
X		}
X	abort();
}
X
main()
{
/*
** Modified by G. Geers - glenn at qed.physics.su.oz.au
**
** Define TEST if you want to include my code
**
*/
X
#ifdef TEST
X	setcont(0x127f);
#endif
X
X	/* First two assignments use integer right-hand sides. */
X	Zero = 0;
X	One = 1;
X	Two = One + One;
X	Three = Two + One;
X	Four = Three + One;
X	Five = Four + One;
X	Eight = Four + Four;
X	Nine = Three * Three;
X	TwentySeven = Nine * Three;
X	ThirtyTwo = Four * Eight;
X	TwoForty = Four * Five * Three * Four;
X	MinusOne = -One;
X	Half = One / Two;
X	OneAndHalf = One + Half;
X	ErrCnt[Failure] = 0;
X	ErrCnt[Serious] = 0;
X	ErrCnt[Defect] = 0;
X	ErrCnt[Flaw] = 0;
X	PageNo = 1;
X	/*=============================================*/
X	Milestone = 0;
X	/*=============================================*/
#ifndef NOSIGNAL
X	signal(SIGFPE, sigfpe);
#endif
X	Instructions();
X	Pause();
X	Heading();
X	Pause();
X	Characteristics();
X	Pause();
X	History();
X	Pause();
X	/*=============================================*/
X	Milestone = 7;
X	/*=============================================*/
X	printf("Program is now RUNNING tests on small integers:\n");
X	
X	TstCond (Failure, (Zero + Zero == Zero) && (One - One == Zero)
X		   && (One > Zero) && (One + One == Two),
X			"0+0 != 0, 1-1 != 0, 1 <= 0, or 1+1 != 2");
X	Z = - Zero;
X	if (Z != 0.0) {
X		ErrCnt[Failure] = ErrCnt[Failure] + 1;
X		printf("Comparison alleges that -0.0 is Non-zero!\n");
X		U1 = 0.001;
X		Radix = 1;
X		TstPtUf();
X		}
X	TstCond (Failure, (Three == Two + One) && (Four == Three + One)
X		   && (Four + Two * (- Two) == Zero)
X		   && (Four - Three - One == Zero),
X		   "3 != 2+1, 4 != 3+1, 4+2*(-2) != 0, or 4-3-1 != 0");
X	TstCond (Failure, (MinusOne == (0 - One))
X		   && (MinusOne + One == Zero ) && (One + MinusOne == Zero)
X		   && (MinusOne + FABS(One) == Zero)
X		   && (MinusOne + MinusOne * MinusOne == Zero),
X		   "-1+1 != 0, (-1)+abs(1) != 0, or -1+(-1)*(-1) != 0");
X	TstCond (Failure, Half + MinusOne + Half == Zero,
X		  "1/2 + (-1) + 1/2 != 0");
X	/*=============================================*/
X	/*SPLIT
X	part2();
X	part3();
X	part4();
X	part5();
X	part6();
X	part7();
X	part8();
X
X	}
#include "paranoia.h"
part2(){
*/
X	Milestone = 10;
X	/*=============================================*/
X	TstCond (Failure, (Nine == Three * Three)
X		   && (TwentySeven == Nine * Three) && (Eight == Four + Four)
X		   && (ThirtyTwo == Eight * Four)
X		   && (ThirtyTwo - TwentySeven - Four - One == Zero),
X		   "9 != 3*3, 27 != 9*3, 32 != 8*4, or 32-27-4-1 != 0");
X	TstCond (Failure, (Five == Four + One) &&
X			(TwoForty == Four * Five * Three * Four)
X		   && (TwoForty / Three - Four * Four * Five == Zero)
X		   && ( TwoForty / Four - Five * Three * Four == Zero)
X		   && ( TwoForty / Five - Four * Three * Four == Zero),
X		  "5 != 4+1, 240/3 != 80, 240/4 != 60, or 240/5 != 48");
X	if (ErrCnt[Failure] == 0) {
X		printf("-1, 0, 1/2, 1, 2, 3, 4, 5, 9, 27, 32 & 240 are O.K.\n");
X		printf("\n");
X		}
X	printf("Searching for Radix and Precision.\n");
X	W = One;
X	do  {
X		W = W + W;
X		Y = W + One;
X		Z = Y - W;
X		Y = Z - One;
X		} while (MinusOne + FABS(Y) < Zero);
X	/*.. now W is just big enough that |((W+1)-W)-1| >= 1 ...*/
X	Precision = Zero;
X	Y = One;
X	do  {
X		Radix = W + Y;
X		Y = Y + Y;
X		Radix = Radix - W;
X		} while ( Radix == Zero);
X	if (Radix < Two) Radix = One;
X	printf("Radix = %f .\n", Radix);
X	if (Radix != 1) {
X		W = One;
X		do  {
X			Precision = Precision + One;
X			W = W * Radix;
X			Y = W + One;
X			} while ((Y - W) == One);
X		}
X	/*... now W == Radix^Precision is barely too big to satisfy (W+1)-W == 1
X			                              ...*/
X	U1 = One / W;
X	U2 = Radix * U1;
X	printf("Closest relative separation found is U1 = %.7e .\n\n", U1);
X	printf("Recalculating radix and precision\n ");
X	
X	/*save old values*/
X	E0 = Radix;
X	E1 = U1;
X	E9 = U2;
X	E3 = Precision;
X	
X	X = Four / Three;
X	Third = X - One;
X	F6 = Half - Third;
X	X = F6 + F6;
X	X = FABS(X - Third);
X	if (X < U2) X = U2;
X	
X	/*... now X = (unknown no.) ulps of 1+...*/
X	do  {
X		U2 = X;
X		Y = Half * U2 + ThirtyTwo * U2 * U2;
X		Y = One + Y;
X		X = Y - One;
X		} while ( ! ((U2 <= X) || (X <= Zero)));
X	
X	/*... now U2 == 1 ulp of 1 + ... */
X	X = Two / Three;
X	F6 = X - Half;
X	Third = F6 + F6;
X	X = Third - Half;
X	X = FABS(X + F6);
X	if (X < U1) X = U1;
X	
X	/*... now  X == (unknown no.) ulps of 1 -... */
X	do  {
X		U1 = X;
X		Y = Half * U1 + ThirtyTwo * U1 * U1;
X		Y = Half - Y;
X		X = Half + Y;
X		Y = Half - X;
X		X = Half + Y;
X		} while ( ! ((U1 <= X) || (X <= Zero)));
X	/*... now U1 == 1 ulp of 1 - ... */
X	if (U1 == E1) printf("confirms closest relative separation U1 .\n");
X	else printf("gets better closest relative separation U1 = %.7e .\n", U1);
X	W = One / U1;
X	F9 = (Half - U1) + Half;
X	Radix = FLOOR(0.01 + U2 / U1);
X	if (Radix == E0) printf("Radix confirmed.\n");
X	else printf("MYSTERY: recalculated Radix = %.7e .\n", Radix);
X	TstCond (Defect, Radix <= Eight + Eight,
X		   "Radix is too big: roundoff problems");
X	TstCond (Flaw, (Radix == Two) || (Radix == 10)
X		   || (Radix == One), "Radix is not as good as 2 or 10");
X	/*=============================================*/
X	Milestone = 20;
X	/*=============================================*/
X	TstCond (Failure, F9 - Half < Half,
X		   "(1-U1)-1/2 < 1/2 is FALSE, prog. fails?");
X	X = F9;
X	I = 1;
X	Y = X - Half;
X	Z = Y - Half;
X	TstCond (Failure, (X != One)
X		   || (Z == Zero), "Comparison is fuzzy,X=1 but X-1/2-1/2 != 0");
X	X = One + U2;
X	I = 0;
X	/*=============================================*/
X	Milestone = 25;
X	/*=============================================*/
X	/*... BMinusU2 = nextafter(Radix, 0) */
X	BMinusU2 = Radix - One;
X	BMinusU2 = (BMinusU2 - U2) + One;
X	/* Purify Integers */
X	if (Radix != One)  {
X		X = - TwoForty * LOG(U1) / LOG(Radix);
X		Y = FLOOR(Half + X);
X		if (FABS(X - Y) * Four < One) X = Y;
X		Precision = X / TwoForty;
X		Y = FLOOR(Half + Precision);
X		if (FABS(Precision - Y) * TwoForty < Half) Precision = Y;
X		}
X	if ((Precision != FLOOR(Precision)) || (Radix == One)) {
X		printf("Precision cannot be characterized by an Integer number\n");
X		printf("of significant digits but, by itself, this is a minor flaw.\n");
X		}
X	if (Radix == One) 
X		printf("logarithmic encoding has precision characterized solely by U1.\n");
X	else printf("The number of significant digits of the Radix is %f .\n",
X			Precision);
X	TstCond (Serious, U2 * Nine * Nine * TwoForty < One,
X		   "Precision worse than 5 decimal figures  ");
X	/*=============================================*/
X	Milestone = 30;
X	/*=============================================*/
X	/* Test for extra-precise subepressions */
X	X = FABS(((Four / Three - One) - One / Four) * Three - One / Four);
X	do  {
X		Z2 = X;
X		X = (One + (Half * Z2 + ThirtyTwo * Z2 * Z2)) - One;
X		} while ( ! ((Z2 <= X) || (X <= Zero)));
X	X = Y = Z = FABS((Three / Four - Two / Three) * Three - One / Four);
X	do  {
X		Z1 = Z;
X		Z = (One / Two - ((One / Two - (Half * Z1 + ThirtyTwo * Z1 * Z1))
X			+ One / Two)) + One / Two;
X		} while ( ! ((Z1 <= Z) || (Z <= Zero)));
X	do  {
X		do  {
X			Y1 = Y;
X			Y = (Half - ((Half - (Half * Y1 + ThirtyTwo * Y1 * Y1)) + Half
X				)) + Half;
X			} while ( ! ((Y1 <= Y) || (Y <= Zero)));
X		X1 = X;
X		X = ((Half * X1 + ThirtyTwo * X1 * X1) - F9) + F9;
X		} while ( ! ((X1 <= X) || (X <= Zero)));
X	if ((X1 != Y1) || (X1 != Z1)) {
X		BadCond(Serious, "Disagreements among the values X1, Y1, Z1,\n");
X		printf("respectively  %.7e,  %.7e,  %.7e,\n", X1, Y1, Z1);
X		printf("are symptoms of inconsistencies introduced\n");
X		printf("by extra-precise evaluation of arithmetic subexpressions.\n");
X		notify("Possibly some part of this");
X		if ((X1 == U1) || (Y1 == U1) || (Z1 == U1))  printf(
X			"That feature is not tested further by this program.\n") ;
X		}
X	else  {
X		if ((Z1 != U1) || (Z2 != U2)) {
X			if ((Z1 >= U1) || (Z2 >= U2)) {
X				BadCond(Failure, "");
X				notify("Precision");
X				printf("\tU1 = %.7e, Z1 - U1 = %.7e\n",U1,Z1-U1);
X				printf("\tU2 = %.7e, Z2 - U2 = %.7e\n",U2,Z2-U2);
X				}
X			else {
X				if ((Z1 <= Zero) || (Z2 <= Zero)) {
X					printf("Because of unusual Radix = %f", Radix);
X					printf(", or exact rational arithmetic a result\n");
X					printf("Z1 = %.7e, or Z2 = %.7e ", Z1, Z2);
X					notify("of an\nextra-precision");
X					}
X				if (Z1 != Z2 || Z1 > Zero) {
X					X = Z1 / U1;
X					Y = Z2 / U2;
X					if (Y > X) X = Y;
X					Q = - LOG(X);
X					printf("Some subexpressions appear to be calculated extra\n");
X					printf("precisely with about %g extra B-digits, i.e.\n",
X						(Q / LOG(Radix)));
X					printf("roughly %g extra significant decimals.\n",
X						Q / LOG(10.));
X					}
X				printf("That feature is not tested further by this program.\n");
X				}
X			}
X		}
X	Pause();
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part3(){
*/
X	Milestone = 35;
X	/*=============================================*/
X	if (Radix >= Two) {
X		X = W / (Radix * Radix);
X		Y = X + One;
X		Z = Y - X;
X		T = Z + U2;
X		X = T - Z;
X		TstCond (Failure, X == U2,
X			"Subtraction is not normalized X=Y,X+Z != Y+Z!");
X		if (X == U2) printf(
X			"Subtraction appears to be normalized, as it should be.");
X		}
X	printf("\nChecking for guard digit in *, /, and -.\n");
X	Y = F9 * One;
X	Z = One * F9;
X	X = F9 - Half;
X	Y = (Y - Half) - X;
X	Z = (Z - Half) - X;
X	X = One + U2;
X	T = X * Radix;
X	R = Radix * X;
X	X = T - Radix;
X	X = X - Radix * U2;
X	T = R - Radix;
X	T = T - Radix * U2;
X	X = X * (Radix - One);
X	T = T * (Radix - One);
X	if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero)) GMult = Yes;
X	else {
X		GMult = No;
X		TstCond (Serious, False,
X			"* lacks a Guard Digit, so 1*X != X");
X		}
X	Z = Radix * U2;
X	X = One + Z;
X	Y = FABS((X + Z) - X * X) - U2;
X	X = One - U2;
X	Z = FABS((X - U2) - X * X) - U1;
X	TstCond (Failure, (Y <= Zero)
X		   && (Z <= Zero), "* gets too many final digits wrong.\n");
X	Y = One - U2;
X	X = One + U2;
X	Z = One / Y;
X	Y = Z - X;
X	X = One / Three;
X	Z = Three / Nine;
X	X = X - Z;
X	T = Nine / TwentySeven;
X	Z = Z - T;
X	TstCond(Defect, X == Zero && Y == Zero && Z == Zero,
X		"Division lacks a Guard Digit, so error can exceed 1 ulp\n\
or  1/3  and  3/9  and  9/27 may disagree");
X	Y = F9 / One;
X	X = F9 - Half;
X	Y = (Y - Half) - X;
X	X = One + U2;
X	T = X / One;
X	X = T - X;
X	if ((X == Zero) && (Y == Zero) && (Z == Zero)) GDiv = Yes;
X	else {
X		GDiv = No;
X		TstCond (Serious, False,
X			"Division lacks a Guard Digit, so X/1 != X");
X		}
X	X = One / (One + U2);
X	Y = X - Half - Half;
X	TstCond (Serious, Y < Zero,
X		   "Computed value of 1/1.000..1 >= 1");
X	X = One - U2;
X	Y = One + Radix * U2;
X	Z = X * Radix;
X	T = Y * Radix;
X	R = Z / Radix;
X	StickyBit = T / Radix;
X	X = R - X;
X	Y = StickyBit - Y;
X	TstCond (Failure, X == Zero && Y == Zero,
X			"* and/or / gets too many last digits wrong");
X	Y = One - U1;
X	X = One - F9;
X	Y = One - Y;
X	T = Radix - U2;
X	Z = Radix - BMinusU2;
X	T = Radix - T;
X	if ((X == U1) && (Y == U1) && (Z == U2) && (T == U2)) GAddSub = Yes;
X	else {
X		GAddSub = No;
X		TstCond (Serious, False,
X			"- lacks Guard Digit, so cancellation is obscured");
X		}
X	if (F9 != One && F9 - One >= Zero) {
X		BadCond(Serious, "comparison alleges  (1-U1) < 1  although\n");
X		printf("  subtraction yields  (1-U1) - 1 = 0 , thereby vitiating\n");
X		printf("  such precautions against division by zero as\n");
X		printf("  ...  if (X == 1.0) {.....} else {.../(X-1.0)...}\n");
X		}
X	if (GMult == Yes && GDiv == Yes && GAddSub == Yes) printf(
X		"     *, /, and - appear to have guard digits, as they should.\n");
X	/*=============================================*/
X	Milestone = 40;
X	/*=============================================*/
X	Pause();
X	printf("Checking rounding on multiply, divide and add/subtract.\n");
X	RMult = Other;
X	RDiv = Other;
X	RAddSub = Other;
X	RadixD2 = Radix / Two;
X	A1 = Two;
X	Done = False;
X	do  {
X		AInvrse = Radix;
X		do  {
X			X = AInvrse;
X			AInvrse = AInvrse / A1;
X			} while ( ! (FLOOR(AInvrse) != AInvrse));
X		Done = (X == One) || (A1 > Three);
X		if (! Done) A1 = Nine + One;
X		} while ( ! (Done));
X	if (X == One) A1 = Radix;
X	AInvrse = One / A1;
X	X = A1;
X	Y = AInvrse;
X	Done = False;
X	do  {
X		Z = X * Y - Half;
X		TstCond (Failure, Z == Half,
X			"X * (1/X) differs from 1");
X		Done = X == Radix;
X		X = Radix;
X		Y = One / X;
X		} while ( ! (Done));
X	Y2 = One + U2;
X	Y1 = One - U2;
X	X = OneAndHalf - U2;
X	Y = OneAndHalf + U2;
X	Z = (X - U2) * Y2;
X	T = Y * Y1;
X	Z = Z - X;
X	T = T - X;
X	X = X * Y2;
X	Y = (Y + U2) * Y1;
X	X = X - OneAndHalf;
X	Y = Y - OneAndHalf;
X	if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T <= Zero)) {
X		X = (OneAndHalf + U2) * Y2;
X		Y = OneAndHalf - U2 - U2;
X		Z = OneAndHalf + U2 + U2;
X		T = (OneAndHalf - U2) * Y1;
X		X = X - (Z + U2);
X		StickyBit = Y * Y1;
X		S = Z * Y2;
X		T = T - Y;
X		Y = (U2 - Y) + StickyBit;
X		Z = S - (Z + U2 + U2);
X		StickyBit = (Y2 + U2) * Y1;
X		Y1 = Y2 * Y1;
X		StickyBit = StickyBit - Y2;
X		Y1 = Y1 - Half;
X		if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero)
X			&& ( StickyBit == Zero) && (Y1 == Half)) {
X			RMult = Rounded;
X			printf("Multiplication appears to round correctly.\n");
X			}
X		else	if ((X + U2 == Zero) && (Y < Zero) && (Z + U2 == Zero)
X				&& (T < Zero) && (StickyBit + U2 == Zero)
X				&& (Y1 < Half)) {
X				RMult = Chopped;
X				printf("Multiplication appears to chop.\n");
X				}
X			else printf("* is neither chopped nor correctly rounded.\n");
X		if ((RMult == Rounded) && (GMult == No)) notify("Multiplication");
X		}
X	else printf("* is neither chopped nor correctly rounded.\n");
X	/*=============================================*/
X	Milestone = 45;
X	/*=============================================*/
X	Y2 = One + U2;
X	Y1 = One - U2;
X	Z = OneAndHalf + U2 + U2;
X	X = Z / Y2;
X	T = OneAndHalf - U2 - U2;
X	Y = (T - U2) / Y1;
X	Z = (Z + U2) / Y2;
X	X = X - OneAndHalf;
X	Y = Y - T;
X	T = T / Y1;
X	Z = Z - (OneAndHalf + U2);
X	T = (U2 - OneAndHalf) + T;
X	if (! ((X > Zero) || (Y > Zero) || (Z > Zero) || (T > Zero))) {
X		X = OneAndHalf / Y2;
X		Y = OneAndHalf - U2;
X		Z = OneAndHalf + U2;
X		X = X - Y;
X		T = OneAndHalf / Y1;
X		Y = Y / Y1;
X		T = T - (Z + U2);
X		Y = Y - Z;
X		Z = Z / Y2;
X		Y1 = (Y2 + U2) / Y2;
X		Z = Z - OneAndHalf;
X		Y2 = Y1 - Y2;
X		Y1 = (F9 - U1) / F9;
X		if ((X == Zero) && (Y == Zero) && (Z == Zero) && (T == Zero)
X			&& (Y2 == Zero) && (Y2 == Zero)
X			&& (Y1 - Half == F9 - Half )) {
X			RDiv = Rounded;
X			printf("Division appears to round correctly.\n");
X			if (GDiv == No) notify("Division");
X			}
X		else if ((X < Zero) && (Y < Zero) && (Z < Zero) && (T < Zero)
X			&& (Y2 < Zero) && (Y1 - Half < F9 - Half)) {
X			RDiv = Chopped;
X			printf("Division appears to chop.\n");
X			}
X		}
X	if (RDiv == Other) printf("/ is neither chopped nor correctly rounded.\n");
X	BInvrse = One / Radix;
X	TstCond (Failure, (BInvrse * Radix - Half == Half),
X		   "Radix * ( 1 / Radix ) differs from 1");
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part4(){
*/
X	Milestone = 50;
X	/*=============================================*/
X	TstCond (Failure, ((F9 + U1) - Half == Half)
X		   && ((BMinusU2 + U2 ) - One == Radix - One),
X		   "Incomplete carry-propagation in Addition");
X	X = One - U1 * U1;
X	Y = One + U2 * (One - U2);
X	Z = F9 - Half;
X	X = (X - Half) - Z;
X	Y = Y - One;
X	if ((X == Zero) && (Y == Zero)) {
X		RAddSub = Chopped;
X		printf("Add/Subtract appears to be chopped.\n");
X		}
X	if (GAddSub == Yes) {
X		X = (Half + U2) * U2;
X		Y = (Half - U2) * U2;
X		X = One + X;
X		Y = One + Y;
X		X = (One + U2) - X;
X		Y = One - Y;
X		if ((X == Zero) && (Y == Zero)) {
X			X = (Half + U2) * U1;
X			Y = (Half - U2) * U1;
X			X = One - X;
X			Y = One - Y;
X			X = F9 - X;
X			Y = One - Y;
X			if ((X == Zero) && (Y == Zero)) {
X				RAddSub = Rounded;
X				printf("Addition/Subtraction appears to round correctly.\n");
X				if (GAddSub == No) notify("Add/Subtract");
X				}
X			else printf("Addition/Subtraction neither rounds nor chops.\n");
X			}
X		else printf("Addition/Subtraction neither rounds nor chops.\n");
X		}
X	else printf("Addition/Subtraction neither rounds nor chops.\n");
X	S = One;
X	X = One + Half * (One + Half);
X	Y = (One + U2) * Half;
X	Z = X - Y;
X	T = Y - X;
X	StickyBit = Z + T;
X	if (StickyBit != Zero) {
X		S = Zero;
X		BadCond(Flaw, "(X - Y) + (Y - X) is non zero!\n");
X		}
X	StickyBit = Zero;
X	if ((GMult == Yes) && (GDiv == Yes) && (GAddSub == Yes)
X		&& (RMult == Rounded) && (RDiv == Rounded)
X		&& (RAddSub == Rounded) && (FLOOR(RadixD2) == RadixD2)) {
X		printf("Checking for sticky bit.\n");
X		X = (Half + U1) * U2;
X		Y = Half * U2;
X		Z = One + Y;
X		T = One + X;
X		if ((Z - One <= Zero) && (T - One >= U2)) {
X			Z = T + Y;
X			Y = Z - X;
X			if ((Z - T >= U2) && (Y - T == Zero)) {
X				X = (Half + U1) * U1;
X				Y = Half * U1;
X				Z = One - Y;
X				T = One - X;
X				if ((Z - One == Zero) && (T - F9 == Zero)) {
X					Z = (Half - U1) * U1;
X					T = F9 - Z;
X					Q = F9 - Y;
X					if ((T - F9 == Zero) && (F9 - U1 - Q == Zero)) {
X						Z = (One + U2) * OneAndHalf;
X						T = (OneAndHalf + U2) - Z + U2;
X						X = One + Half / Radix;
X						Y = One + Radix * U2;
X						Z = X * Y;
X						if (T == Zero && X + Radix * U2 - Z == Zero) {
X							if (Radix != Two) {
X								X = Two + U2;
X								Y = X / Two;
X								if ((Y - One == Zero)) StickyBit = S;
X								}
X							else StickyBit = S;
X							}
X						}
X					}
X				}
X			}
X		}
X	if (StickyBit == One) printf("Sticky bit apparently used correctly.\n");
X	else printf("Sticky bit used incorrectly or not at all.\n");
X	TstCond (Flaw, !(GMult == No || GDiv == No || GAddSub == No ||
X			RMult == Other || RDiv == Other || RAddSub == Other),
X		"lack(s) of guard digits or failure(s) to correctly round or chop\n\
(noted above) count as one flaw in the final tally below");
X	/*=============================================*/
X	Milestone = 60;
X	/*=============================================*/
X	printf("\n");
X	printf("Does Multiplication commute?  ");
X	printf("Testing on %d random pairs.\n", NoTrials);
X	Random9 = SQRT(3.0);
X	Random1 = Third;
X	I = 1;
X	do  {
X		X = Random();
X		Y = Random();
X		Z9 = Y * X;
X		Z = X * Y;
X		Z9 = Z - Z9;
X		I = I + 1;
X		} while ( ! ((I > NoTrials) || (Z9 != Zero)));
X	if (I == NoTrials) {
X		Random1 = One + Half / Three;
X		Random2 = (U2 + U1) + One;
X		Z = Random1 * Random2;
X		Y = Random2 * Random1;
X		Z9 = (One + Half / Three) * ((U2 + U1) + One) - (One + Half /
X			Three) * ((U2 + U1) + One);
X		}
X	if (! ((I == NoTrials) || (Z9 == Zero)))
X		BadCond(Defect, "X * Y == Y * X trial fails.\n");
X	else printf("     No failures found in %d integer pairs.\n", NoTrials);
X	/*=============================================*/
X	Milestone = 70;
X	/*=============================================*/
X	printf("\nRunning test of square root(x).\n");
X	TstCond (Failure, (Zero == SQRT(Zero))
X		   && (- Zero == SQRT(- Zero))
X		   && (One == SQRT(One)), "Square root of 0.0, -0.0 or 1.0 wrong");
X	MinSqEr = Zero;
X	MaxSqEr = Zero;
X	J = Zero;
X	X = Radix;
X	OneUlp = U2;
X	SqXMinX (Serious);
X	X = BInvrse;
X	OneUlp = BInvrse * U1;
X	SqXMinX (Serious);
X	X = U1;
X	OneUlp = U1 * U1;
X	SqXMinX (Serious);
X	if (J != Zero) Pause();
X	printf("Testing if sqrt(X * X) == X for %d Integers X.\n", NoTrials);
X	J = Zero;
X	X = Two;
X	Y = Radix;
X	if ((Radix != One)) do  {
X		X = Y;
X		Y = Radix * Y;
X		} while ( ! ((Y - X >= NoTrials)));
X	OneUlp = X * U2;
X	I = 1;
X	while (I <= NoTrials) {
X		X = X + One;
X		SqXMinX (Defect);
X		if (J > Zero) break;
X		I = I + 1;
X		}
X	printf("Test for sqrt monotonicity.\n");
X	I = - 1;
X	X = BMinusU2;
X	Y = Radix;
X	Z = Radix + Radix * U2;
X	NotMonot = False;
X	Monot = False;
X	while ( ! (NotMonot || Monot)) {
X		I = I + 1;
X		X = SQRT(X);
X		Q = SQRT(Y);
X		Z = SQRT(Z);
X		if ((X > Q) || (Q > Z)) NotMonot = True;
X		else {
X			Q = FLOOR(Q + Half);
X			if ((I > 0) || (Radix == Q * Q)) Monot = True;
X			else if (I > 0) {
X			if (I > 1) Monot = True;
X			else {
X				Y = Y * BInvrse;
X				X = Y - U1;
X				Z = Y + U1;
X				}
X			}
X			else {
X				Y = Q;
X				X = Y - U2;
X				Z = Y + U2;
X				}
X			}
X		}
X	if (Monot) printf("sqrt has passed a test for Monotonicity.\n");
X	else {
X		BadCond(Defect, "");
X		printf("sqrt(X) is non-monotonic for X near %.7e .\n", Y);
X		}
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part5(){
*/
X	Milestone = 80;
X	/*=============================================*/
X	MinSqEr = MinSqEr + Half;
X	MaxSqEr = MaxSqEr - Half;
X	Y = (SQRT(One + U2) - One) / U2;
X	SqEr = (Y - One) + U2 / Eight;
X	if (SqEr > MaxSqEr) MaxSqEr = SqEr;
X	SqEr = Y + U2 / Eight;
X	if (SqEr < MinSqEr) MinSqEr = SqEr;
X	Y = ((SQRT(F9) - U2) - (One - U2)) / U1;
X	SqEr = Y + U1 / Eight;
X	if (SqEr > MaxSqEr) MaxSqEr = SqEr;
X	SqEr = (Y + One) + U1 / Eight;
X	if (SqEr < MinSqEr) MinSqEr = SqEr;
X	OneUlp = U2;
X	X = OneUlp;
X	for( Indx = 1; Indx <= 3; ++Indx) {
X		Y = SQRT((X + U1 + X) + F9);
X		Y = ((Y - U2) - ((One - U2) + X)) / OneUlp;
X		Z = ((U1 - X) + F9) * Half * X * X / OneUlp;
X		SqEr = (Y + Half) + Z;
X		if (SqEr < MinSqEr) MinSqEr = SqEr;
X		SqEr = (Y - Half) + Z;
X		if (SqEr > MaxSqEr) MaxSqEr = SqEr;
X		if (((Indx == 1) || (Indx == 3))) 
X			X = OneUlp * Sign (X) * FLOOR(Eight / (Nine * SQRT(OneUlp)));
X		else {
X			OneUlp = U1;
X			X = - OneUlp;
X			}
X		}
X	/*=============================================*/
X	Milestone = 85;
X	/*=============================================*/
X	SqRWrng = False;
X	Anomaly = False;
X	RSqrt = Other; /* ~dgh */
X	if (Radix != One) {
X		printf("Testing whether sqrt is rounded or chopped.\n");
X		D = FLOOR(Half + POW(Radix, One + Precision - FLOOR(Precision)));
X	/* ... == Radix^(1 + fract) if (Precision == Integer + fract. */
X		X = D / Radix;
X		Y = D / A1;
X		if ((X != FLOOR(X)) || (Y != FLOOR(Y))) {
X			Anomaly = True;
X			}
X		else {
X			X = Zero;
X			Z2 = X;
X			Y = One;
X			Y2 = Y;
X			Z1 = Radix - One;
X			FourD = Four * D;
X			do  {
X				if (Y2 > Z2) {
X					Q = Radix;
X					Y1 = Y;
X					do  {
X						X1 = FABS(Q + FLOOR(Half - Q / Y1) * Y1);
X						Q = Y1;
X						Y1 = X1;
X						} while ( ! (X1 <= Zero));
X					if (Q <= One) {
X						Z2 = Y2;
X						Z = Y;
X						}
X					}
X				Y = Y + Two;
X				X = X + Eight;
X				Y2 = Y2 + X;
X				if (Y2 >= FourD) Y2 = Y2 - FourD;
X				} while ( ! (Y >= D));
X			X8 = FourD - Z2;
X			Q = (X8 + Z * Z) / FourD;
X			X8 = X8 / Eight;
X			if (Q != FLOOR(Q)) Anomaly = True;
X			else {
X				Break = False;
X				do  {
X					X = Z1 * Z;
X					X = X - FLOOR(X / Radix) * Radix;
X					if (X == One) 
X						Break = True;
X					else
X						Z1 = Z1 - One;
X					} while ( ! (Break || (Z1 <= Zero)));
X				if ((Z1 <= Zero) && (! Break)) Anomaly = True;
X				else {
X					if (Z1 > RadixD2) Z1 = Z1 - Radix;
X					do  {
X						NewD();
X						} while ( ! (U2 * D >= F9));
X					if (D * Radix - D != W - D) Anomaly = True;
X					else {
X						Z2 = D;
X						I = 0;
X						Y = D + (One + Z) * Half;
X						X = D + Z + Q;
X						SR3750();
X						Y = D + (One - Z) * Half + D;
X						X = D - Z + D;
X						X = X + Q + X;
X						SR3750();
X						NewD();
X						if (D - Z2 != W - Z2) Anomaly = True;
X						else {
X							Y = (D - Z2) + (Z2 + (One - Z) * Half);
X							X = (D - Z2) + (Z2 - Z + Q);
X							SR3750();
X							Y = (One + Z) * Half;
X							X = Q;
X							SR3750();
X							if (I == 0) Anomaly = True;
X							}
X						}
X					}
X				}
X			}
X		if ((I == 0) || Anomaly) {
X			BadCond(Failure, "Anomalous arithmetic with Integer < ");
X			printf("Radix^Precision = %.7e\n", W);
X			printf(" fails test whether sqrt rounds or chops.\n");
X			SqRWrng = True;
X			}
X		}
X	if (! Anomaly) {
X		if (! ((MinSqEr < Zero) || (MaxSqEr > Zero))) {
X			RSqrt = Rounded;
X			printf("Square root appears to be correctly rounded.\n");
X			}
X		else  {
X			if ((MaxSqEr + U2 > U2 - Half) || (MinSqEr > Half)
X				|| (MinSqEr + Radix < Half)) SqRWrng = True;
X			else {
X				RSqrt = Chopped;
X				printf("Square root appears to be chopped.\n");
X				}
X			}
X		}
X	if (SqRWrng) {
X		printf("Square root is neither chopped nor correctly rounded.\n");
X		printf("Observed errors run from %.7e ", MinSqEr - Half);
X		printf("to %.7e ulps.\n", Half + MaxSqEr);
X		TstCond (Serious, MaxSqEr - MinSqEr < Radix * Radix,
X			"sqrt gets too many last digits wrong");
X		}
X	/*=============================================*/
X	Milestone = 90;
X	/*=============================================*/
X	Pause();
X	printf("Testing powers Z^i for small Integers Z and i.\n");
X	N = 0;
X	/* ... test powers of zero. */
X	I = 0;
X	Z = -Zero;
X	M = 3.0;
X	Break = False;
X	do  {
X		X = One;
X		SR3980();
X		if (I <= 10) {
X			I = 1023;
X			SR3980();
X			}
X		if (Z == MinusOne) Break = True;
X		else {
X			Z = MinusOne;
X			PrintIfNPositive();
X			N = 0;
X			/* .. if(-1)^N is invalid, replace MinusOne by One. */
X			I = - 4;
X			}
X		} while ( ! Break);
X	PrintIfNPositive();
X	N1 = N;
X	N = 0;
X	Z = A1;
X	M = FLOOR(Two * LOG(W) / LOG(A1));
X	Break = False;
X	do  {
X		X = Z;
X		I = 1;
X		SR3980();
X		if (Z == AInvrse) Break = True;
X		else Z = AInvrse;
X		} while ( ! (Break));
X	/*=============================================*/
X		Milestone = 100;
X	/*=============================================*/
X	/*  Powers of Radix have been tested, */
X	/*         next try a few primes     */
X	M = NoTrials;
X	Z = Three;
X	do  {
X		X = Z;
X		I = 1;
X		SR3980();
X		do  {
X			Z = Z + Two;
X			} while ( Three * FLOOR(Z / Three) == Z );
X		} while ( Z < Eight * Three );
X	if (N > 0) {
X		printf("Errors like this may invalidate financial calculations\n");
X		printf("\tinvolving interest rates.\n");
X		}
X	PrintIfNPositive();
X	N += N1;
X	if (N == 0) printf("... no discrepancis found.\n");
X	if (N > 0) Pause();
X	else printf("\n");
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part6(){
*/
X	Milestone = 110;
X	/*=============================================*/
X	printf("Seeking Underflow thresholds UfThold and E0.\n");
X	D = U1;
X	if (Precision != FLOOR(Precision)) {
X		D = BInvrse;
X		X = Precision;
X		do  {
X			D = D * BInvrse;
X			X = X - One;
X			} while ( X > Zero);
X		}
X	Y = One;
X	Z = D;
X	/* ... D is power of 1/Radix < 1. */
X	do  {
X		C = Y;
X		Y = Z;
X		Z = Y * Y;
X		} while ((Y > Z) && (Z + Z > Z));
X	Y = C;
X	Z = Y * D;
X	do  {
X		C = Y;
X		Y = Z;
X		Z = Y * D;
X		} while ((Y > Z) && (Z + Z > Z));
X	if (Radix < Two) HInvrse = Two;
X	else HInvrse = Radix;
X	H = One / HInvrse;
X	/* ... 1/HInvrse == H == Min(1/Radix, 1/2) */
X	CInvrse = One / C;
X	E0 = C;
X	Z = E0 * H;
X	/* ...1/Radix^(BIG Integer) << 1 << CInvrse == 1/C */
X	do  {
X		Y = E0;
X		E0 = Z;
X		Z = E0 * H;
X		} while ((E0 > Z) && (Z + Z > Z));
X	UfThold = E0;
X	E1 = Zero;
X	Q = Zero;
X	E9 = U2;
X	S = One + E9;
X	D = C * S;
X	if (D <= C) {
X		E9 = Radix * U2;
X		S = One + E9;
X		D = C * S;
X		if (D <= C) {
X			BadCond(Failure, "multiplication gets too many last digits wrong.\n");
X			Underflow = E0;
X			Y1 = Zero;
X			PseudoZero = Z;
X			Pause();
X			}
X		}
X	else {
X		Underflow = D;
X		PseudoZero = Underflow * H;
X		UfThold = Zero;
X		do  {
X			Y1 = Underflow;
X			Underflow = PseudoZero;
X			if (E1 + E1 <= E1) {
X				Y2 = Underflow * HInvrse;
X				E1 = FABS(Y1 - Y2);
X				Q = Y1;
X				if ((UfThold == Zero) && (Y1 != Y2)) UfThold = Y1;
X				}
X			PseudoZero = PseudoZero * H;
X			} while ((Underflow > PseudoZero)
X				&& (PseudoZero + PseudoZero > PseudoZero));
X		}
X	/* Comment line 4530 .. 4560 */
X	if (PseudoZero != Zero) {
X		printf("\n");
X		Z = PseudoZero;
X	/* ... Test PseudoZero for "phoney- zero" violates */
X	/* ... PseudoZero < Underflow or PseudoZero < PseudoZero + PseudoZero
X		   ... */
X		if (PseudoZero <= Zero) {
X			BadCond(Failure, "Positive expressions can underflow to an\n");
X			printf("allegedly negative value\n");
X			printf("PseudoZero that prints out as: %g .\n", PseudoZero);
X			X = - PseudoZero;
X			if (X <= Zero) {
X				printf("But -PseudoZero, which should be\n");
X				printf("positive, isn't; it prints out as  %g .\n", X);
X				}
X			}
X		else {
X			BadCond(Flaw, "Underflow can stick at an allegedly positive\n");
X			printf("value PseudoZero that prints out as %g .\n", PseudoZero);
X			}
X		TstPtUf();
X		}
X	/*=============================================*/
X	Milestone = 120;
X	/*=============================================*/
X	if (CInvrse * Y > CInvrse * Y1) {
X		S = H * S;
X		E0 = Underflow;
X		}
X	if (! ((E1 == Zero) || (E1 == E0))) {
X		BadCond(Defect, "");
X		if (E1 < E0) {
X			printf("Products underflow at a higher");
X			printf(" threshold than differences.\n");
X			if (PseudoZero == Zero) 
X			E0 = E1;
X			}
X		else {
X			printf("Difference underflows at a higher");
X			printf(" threshold than products.\n");
X			}
X		}
X	printf("Smallest strictly positive number found is E0 = %g .\n", E0);
X	Z = E0;
X	TstPtUf();
X	Underflow = E0;
X	if (N == 1) Underflow = Y;
X	I = 4;
X	if (E1 == Zero) I = 3;
X	if (UfThold == Zero) I = I - 2;
X	UfNGrad = True;
X	switch (I)  {
X		case	1:
X		UfThold = Underflow;
X		if ((CInvrse * Q) != ((CInvrse * Y) * S)) {
X			UfThold = Y;
X			BadCond(Failure, "Either accuracy deteriorates as numbers\n");
X			printf("approach a threshold = %.17e\n", UfThold);;
X			printf(" coming down from %.17e\n", C);
X			printf(" or else multiplication gets too many last digits wrong.\n");
X			}
X		Pause();
X		break;
X	
X		case	2:
X		BadCond(Failure, "Underflow confuses Comparison, which alleges that\n");
X		printf("Q == Y while denying that |Q - Y| == 0; these values\n");
X		printf("print out as Q = %.17e, Y = %.17e .\n", Q, Y2);
X		printf ("|Q - Y| = %.17e .\n" , FABS(Q - Y2));
X		UfThold = Q;
X		break;
X	
X		case	3:
X		X = X;
X		break;
X	
X		case	4:
X		if ((Q == UfThold) && (E1 == E0)
X			&& (FABS( UfThold - E1 / E9) <= E1)) {
X			UfNGrad = False;
X			printf("Underflow is gradual; it incurs Absolute Error =\n");
X			printf("(roundoff in UfThold) < E0.\n");
X			Y = E0 * CInvrse;
X			Y = Y * (OneAndHalf + U2);
X			X = CInvrse * (One + U2);
X			Y = Y / X;
X			IEEE = (Y == E0);
X			}
X		}
X	if (UfNGrad) {
X		printf("\n");
X		sigsave = sigfpe;
X		if (setjmp(ovfl_buf)) {
X			printf("Underflow / UfThold failed!\n");
X			R = H + H;
X			}
X		else R = SQRT(Underflow / UfThold);
X		sigsave = 0;
X		if (R <= H) {
X			Z = R * UfThold;
X			X = Z * (One + R * H * (One + H));
X			}
X		else {
X			Z = UfThold;
X			X = Z * (One + H * H * (One + H));
X			}
X		if (! ((X == Z) || (X - Z != Zero))) {
X			BadCond(Flaw, "");
X			printf("X = %.17e\n\tis not equal to Z = %.17e .\n", X, Z);
X			Z9 = X - Z;
X			printf("yet X - Z yields %.17e .\n", Z9);
X			printf("    Should this NOT signal Underflow, ");
X			printf("this is a SERIOUS DEFECT\nthat causes ");
X			printf("confusion when innocent statements like\n");;
X			printf("    if (X == Z)  ...  else");
X			printf("  ... (f(X) - f(Z)) / (X - Z) ...\n");
X			printf("encounter Division by Zero although actually\n");
X			sigsave = sigfpe;
X			if (setjmp(ovfl_buf)) printf("X / Z fails!\n");
X			else printf("X / Z = 1 + %g .\n", (X / Z - Half) - Half);
X			sigsave = 0;
X			}
X		}
X	printf("The Underflow threshold is %.17e, %s\n", UfThold,
X		   " below which");
X	printf("calculation may suffer larger Relative error than ");
X	printf("merely roundoff.\n");
X	Y2 = U1 * U1;
X	Y = Y2 * Y2;
X	Y2 = Y * U1;
X	if (Y2 <= UfThold) {
X		if (Y > E0) {
X			BadCond(Defect, "");
X			I = 5;
X			}
X		else {
X			BadCond(Serious, "");
X			I = 4;
X			}
X		printf("Range is too narrow; U1^%d Underflows.\n", I);
X		}
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part7(){
*/
X	Milestone = 130;
X	/*=============================================*/
X	Y = - FLOOR(Half - TwoForty * LOG(UfThold) / LOG(HInvrse)) / TwoForty;
X	Y2 = Y + Y;
X	printf("Since underflow occurs below the threshold\n");
X	printf("UfThold = (%.17e) ^ (%.17e)\nonly underflow ", HInvrse, Y);
X	printf("should afflict the expression\n\t(%.17e) ^ (%.17e);\n", HInvrse, Y);
X	V9 = POW(HInvrse, Y2);
X	printf("actually calculating yields: %.17e .\n", V9);
X	if (! ((V9 >= Zero) && (V9 <= (Radix + Radix + E9) * UfThold))) {
X		BadCond(Serious, "this is not between 0 and underflow\n");
X		printf("   threshold = %.17e .\n", UfThold);
X		}
X	else if (! (V9 > UfThold * (One + E9)))
X		printf("This computed value is O.K.\n");
X	else {
X		BadCond(Defect, "this is not between 0 and underflow\n");
X		printf("   threshold = %.17e .\n", UfThold);
X		}
X	/*=============================================*/
X	Milestone = 140;
X	/*=============================================*/
X	printf("\n");
X	/* ...calculate Exp2 == exp(2) == 7.389056099... */
X	X = Zero;
X	I = 2;
X	Y = Two * Three;
X	Q = Zero;
X	N = 0;
X	do  {
X		Z = X;
X		I = I + 1;
X		Y = Y / (I + I);
X		R = Y + Q;
X		X = Z + R;
X		Q = (Z - X) + R;
X		} while(X > Z);
X	Z = (OneAndHalf + One / Eight) + X / (OneAndHalf * ThirtyTwo);
X	X = Z * Z;
X	Exp2 = X * X;
X	X = F9;
X	Y = X - U1;
X	printf("Testing X^((X + 1) / (X - 1)) vs. exp(2) = %.17e as X -> 1.\n",
X		Exp2);
X	for(I = 1;;) {
X		Z = X - BInvrse;
X		Z = (X + One) / (Z - (One - BInvrse));
X		Q = POW(X, Z) - Exp2;
X		if (FABS(Q) > TwoForty * U2) {
X			N = 1;
X	 		V9 = (X - BInvrse) - (One - BInvrse);
X			BadCond(Defect, "Calculated");
X			printf(" %.17e for\n", POW(X,Z));
X			printf("\t(1 + (%.17e) ^ (%.17e);\n", V9, Z);
X			printf("\tdiffers from correct value by %.17e .\n", Q);
X			printf("\tThis much error may spoil financial\n");
X			printf("\tcalculations involving tiny interest rates.\n");
X			break;
X			}
X		else {
X			Z = (Y - X) * Two + Y;
X			X = Y;
X			Y = Z;
X			Z = One + (X - F9)*(X - F9);
X			if (Z > One && I < NoTrials) I++;
X			else  {
X				if (X > One) {
X					if (N == 0)
X					   printf("Accuracy seems adequate.\n");
X					break;
X					}
X				else {
X					X = One + U2;
X					Y = U2 + U2;
X					Y += X;
X					I = 1;
X					}
X				}
X			}
X		}
X	/*=============================================*/
X	Milestone = 150;
X	/*=============================================*/
X	printf("Testing powers Z^Q at four nearly extreme values.\n");
X	N = 0;
X	Z = A1;
X	Q = FLOOR(Half - LOG(C) / LOG(A1));
X	Break = False;
X	do  {
X		X = CInvrse;
X		Y = POW(Z, Q);
X		IsYeqX();
X		Q = - Q;
X		X = C;
X		Y = POW(Z, Q);
X		IsYeqX();
X		if (Z < One) Break = True;
X		else Z = AInvrse;
X		} while ( ! (Break));
X	PrintIfNPositive();
X	if (N == 0) printf(" ... no discrepancies found.\n");
X	printf("\n");
X	
X	/*=============================================*/
X	Milestone = 160;
X	/*=============================================*/
X	Pause();
X	printf("Searching for Overflow threshold:\n");
X	printf("This may generate an error.\n");
X	Y = - CInvrse;
X	V9 = HInvrse * Y;
X	sigsave = sigfpe;
X	if (setjmp(ovfl_buf)) { I = 0; V9 = Y; goto overflow; }
X	do {
X		V = Y;
X		Y = V9;
X		V9 = HInvrse * Y;
X		} while(V9 < Y);
X	I = 1;
overflow:
X	sigsave = 0;
X	Z = V9;
X	printf("Can `Z = -Y' overflow?\n");
X	printf("Trying it on Y = %.17e .\n", Y);
X	V9 = - Y;
X	V0 = V9;
X	if (V - Y == V + V0) printf("Seems O.K.\n");
X	else {
X		printf("finds a ");
X		BadCond(Flaw, "-(-Y) differs from Y.\n");
X		}
X	if (Z != Y) {
X		BadCond(Serious, "");
X		printf("overflow past %.17e\n\tshrinks to %.17e .\n", Y, Z);
X		}
X	if (I) {
X		Y = V * (HInvrse * U2 - HInvrse);
X		Z = Y + ((One - HInvrse) * U2) * V;
X		if (Z < V0) Y = Z;
X		if (Y < V0) V = Y;
X		if (V0 - V < V0) V = V0;
X		}
X	else {
X		V = Y * (HInvrse * U2 - HInvrse);
X		V = V + ((One - HInvrse) * U2) * Y;
X		}
X	printf("Overflow threshold is V  = %.17e .\n", V);
X	if (I) printf("Overflow saturates at V0 = %.17e .\n", V0);
X	else printf("There is no saturation value because \
the system traps on overflow.\n");
X	V9 = V * One;
X	printf("No Overflow should be signaled for V * 1 = %.17e\n", V9);
X	V9 = V / One;
X	printf("                           nor for V / 1 = %.17e .\n", V9);
X	printf("Any overflow signal separating this * from the one\n");
X	printf("above is a DEFECT.\n");
X	/*=============================================*/
X	Milestone = 170;
X	/*=============================================*/
X	if (!(-V < V && -V0 < V0 && -UfThold < V && UfThold < V)) {
X		BadCond(Failure, "Comparisons involving ");
X		printf("+-%g, +-%g\nand +-%g are confused by Overflow.",
X			V, V0, UfThold);
X		}
X	/*=============================================*/
X	Milestone = 175;
X	/*=============================================*/
X	printf("\n");
X	for(Indx = 1; Indx <= 3; ++Indx) {
X		switch (Indx)  {
X			case 1: Z = UfThold; break;
X			case 2: Z = E0; break;
X			case 3: Z = PseudoZero; break;
X			}
X		if (Z != Zero) {
X			V9 = SQRT(Z);
X			Y = V9 * V9;
X			if (Y / (One - Radix * E9) < Z
X			   || Y > (One + Radix * E9) * Z) { /* dgh: + E9 --> * E9 */
X				if (V9 > U1) BadCond(Serious, "");
X				else BadCond(Defect, "");
X				printf("Comparison alleges that what prints as Z = %.17e\n", Z);
X				printf(" is too far from sqrt(Z) ^ 2 = %.17e .\n", Y);
X				}
X			}
X		}
X	/*=============================================*/
X	Milestone = 180;
X	/*=============================================*/
X	for(Indx = 1; Indx <= 2; ++Indx) {
X		if (Indx == 1) Z = V;
X		else Z = V0;
X		V9 = SQRT(Z);
X		X = (One - Radix * E9) * V9;
X		V9 = V9 * X;
X		if (((V9 < (One - Two * Radix * E9) * Z) || (V9 > Z))) {
X			Y = V9;
X			if (X < W) BadCond(Serious, "");
X			else BadCond(Defect, "");
X			printf("Comparison alleges that Z = %17e\n", Z);
X			printf(" is too far from sqrt(Z) ^ 2 (%.17e) .\n", Y);
X			}
X		}
X	/*=============================================*/
X	/*SPLIT
X	}
#include "paranoia.h"
part8(){
*/
X	Milestone = 190;
X	/*=============================================*/
X	Pause();
X	X = UfThold * V;
X	Y = Radix * Radix;
X	if (X*Y < One || X > Y) {
X		if (X * Y < U1 || X > Y/U1) BadCond(Defect, "Badly");
X		else BadCond(Flaw, "");
X			
X		printf(" unbalanced range; UfThold * V = %.17e\n\t%s\n",
X			X, "is too far from 1.\n");
X		}
X	/*=============================================*/
X	Milestone = 200;
X	/*=============================================*/
X	for (Indx = 1; Indx <= 5; ++Indx)  {
X		X = F9;
X		switch (Indx)  {
X			case 2: X = One + U2; break;
X			case 3: X = V; break;
X			case 4: X = UfThold; break;
X			case 5: X = Radix;
X			}
X		Y = X;
X		sigsave = sigfpe;
X		if (setjmp(ovfl_buf))
X			printf("  X / X  traps when X = %g\n", X);
X		else {
X			V9 = (Y / X - Half) - Half;
X			if (V9 == Zero) continue;
X			if (V9 == - U1 && Indx < 5) BadCond(Flaw, "");
X			else BadCond(Serious, "");
X			printf("  X / X differs from 1 when X = %.17e\n", X);
X			printf("  instead, X / X - 1/2 - 1/2 = %.17e .\n", V9);
X			}
X		sigsave = 0;
X		}
X	/*=============================================*/
X	Milestone = 210;
X	/*=============================================*/
X	MyZero = Zero;
X	printf("\n");
X	printf("What message and/or values does Division by Zero produce?\n") ;
#ifndef NOPAUSE
X	printf("This can interupt your program.  You can ");
X	printf("skip this part if you wish.\n");
X	printf("Do you wish to compute 1 / 0? ");
X	fflush(stdout);
X	read (KEYBOARD, ch, 8);
X	if ((ch[0] == 'Y') || (ch[0] == 'y')) {
#endif
X		sigsave = sigfpe;
X		printf("    Trying to compute 1 / 0 produces ...");
X		if (!setjmp(ovfl_buf)) printf("  %.7e .\n", One / MyZero);
X		sigsave = 0;
#ifndef NOPAUSE
X		}
X	else printf("O.K.\n");
X	printf("\nDo you wish to compute 0 / 0? ");
X	fflush(stdout);
X	read (KEYBOARD, ch, 80);
X	if ((ch[0] == 'Y') || (ch[0] == 'y')) {
#endif
X		sigsave = sigfpe;
X		printf("\n    Trying to compute 0 / 0 produces ...");
X		if (!setjmp(ovfl_buf)) printf("  %.7e .\n", Zero / MyZero);
X		sigsave = 0;
#ifndef NOPAUSE
X		}
X	else printf("O.K.\n");
#endif
X	/*=============================================*/
X	Milestone = 220;
X	/*=============================================*/
X	Pause();
X	printf("\n");
X	{
X		static char *msg[] = {
X			"FAILUREs  encountered =",
X			"SERIOUS DEFECTs  discovered =",
X			"DEFECTs  discovered =",
X			"FLAWs  discovered =" };
X		int i;
X		for(i = 0; i < 4; i++) if (ErrCnt[i])
X			printf("The number of  %-29s %d.\n",
X				msg[i], ErrCnt[i]);
X		}
X	printf("\n");
X	if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[Defect]
X			+ ErrCnt[Flaw]) > 0) {
X		if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[
X			Defect] == 0) && (ErrCnt[Flaw] > 0)) {
X			printf("The arithmetic diagnosed seems ");
X			printf("Satisfactory though flawed.\n");
X			}
X		if ((ErrCnt[Failure] + ErrCnt[Serious] == 0)
X			&& ( ErrCnt[Defect] > 0)) {
X			printf("The arithmetic diagnosed may be Acceptable\n");
X			printf("despite inconvenient Defects.\n");
X			}
X		if ((ErrCnt[Failure] + ErrCnt[Serious]) > 0) {
X			printf("The arithmetic diagnosed has ");
X			printf("unacceptable Serious Defects.\n");
X			}
X		if (ErrCnt[Failure] > 0) {
X			printf("Potentially fatal FAILURE may have spoiled this");
X			printf(" program's subsequent diagnoses.\n");
X			}
X		}
X	else {
X		printf("No failures, defects nor flaws have been discovered.\n");
X		if (! ((RMult == Rounded) && (RDiv == Rounded)
X			&& (RAddSub == Rounded) && (RSqrt == Rounded))) 
X			printf("The arithmetic diagnosed seems Satisfactory.\n");
X		else {
X			if (StickyBit >= One &&
X				(Radix - Two) * (Radix - Nine - One) == Zero) {
X				printf("Rounding appears to conform to ");
X				printf("the proposed IEEE standard P");
X				if ((Radix == Two) &&
X					 ((Precision - Four * Three * Two) *
X					  ( Precision - TwentySeven -
X					   TwentySeven + One) == Zero)) 
X					printf("754");
X				else printf("854");
X				if (IEEE) printf(".\n");
X				else {
X					printf(",\nexcept for possibly Double Rounding");
X					printf(" during Gradual Underflow.\n");
X					}
X				}
X			printf("The arithmetic diagnosed appears to be Excellent!\n");
X			}
X		}
X	if (fpecount)
X		printf("\nA total of %d floating point exceptions were registered.\n",
X			fpecount);
X	printf("END OF TEST.\n");
X
#ifdef TEST
X	ieee_retrospective((FILE *)NULL);
#endif
X	asm("fnclex");
X        return(0);
X	}
X
/*SPLIT subs.c
#include "paranoia.h"
*/
X
/* Sign */
X
FLOAT Sign (X)
FLOAT X;
{ return X >= 0. ? 1.0 : -1.0; }
X
/* Pause */
X
Pause()
{
#ifndef NOPAUSE
X	char ch[8];
X
X	printf("\nTo continue, press RETURN");
X	fflush(stdout);
X	read(KEYBOARD, ch, 8);
#endif
X	printf("\nDiagnosis resumes after milestone Number %d", Milestone);
X	printf("          Page: %d\n\n", PageNo);
X	++Milestone;
X	++PageNo;
X	}
X
X /* TstCond */
X
TstCond (K, Valid, T)
int K, Valid;
char *T;
{ if (! Valid) { BadCond(K,T); printf(".\n"); } }
X
BadCond(K, T)
int K;
char *T;
{
X	static char *msg[] = { "FAILURE", "SERIOUS DEFECT", "DEFECT", "FLAW" };
X
X	ErrCnt [K] = ErrCnt [K] + 1;
X	printf("%s:  %s", msg[K], T);
X	}
X
/* Random */
/*  Random computes
X     X = (Random1 + Random9)^5
X     Random1 = X - FLOOR(X) + 0.000005 * X;
X   and returns the new value of Random1
*/
X
FLOAT Random()
{
X	FLOAT X, Y;
X	
X	X = Random1 + Random9;
X	Y = X * X;
X	Y = Y * Y;
X	X = X * Y;
X	Y = X - FLOOR(X);
X	Random1 = Y + X * 0.000005;
X	return(Random1);
X	}
X
/* SqXMinX */
X
SqXMinX (ErrKind)
int ErrKind;
{
X	FLOAT XA, XB;
X	
X	XB = X * BInvrse;
X	XA = X - XB;
X	SqEr = ((SQRT(X * X) - XB) - XA) / OneUlp;
X	if (SqEr != Zero) {
X		if (SqEr < MinSqEr) MinSqEr = SqEr;
X		if (SqEr > MaxSqEr) MaxSqEr = SqEr;
X		J = J + 1.0;
X		BadCond(ErrKind, "\n");
X		printf("sqrt( %.17e) - %.17e  = %.17e\n", X * X, X, OneUlp * SqEr);
X		printf("\tinstead of correct value 0 .\n");
X		}
X	}
X
/* NewD */
X
NewD()
{
X	X = Z1 * Q;
X	X = FLOOR(Half - X / Radix) * Radix + X;
X	Q = (Q - X * Z) / Radix + X * X * (D / Radix);
X	Z = Z - Two * X * D;
X	if (Z <= Zero) {
X		Z = - Z;
X		Z1 = - Z1;
X		}
X	D = Radix * D;
X	}
X
/* SR3750 */
X
SR3750()
{
X	if (! ((X - Radix < Z2 - Radix) || (X - Z2 > W - Z2))) {
X		I = I + 1;
X		X2 = SQRT(X * D);
X		Y2 = (X2 - Z2) - (Y - Z2);
X		X2 = X8 / (Y - Half);
X		X2 = X2 - Half * X2 * X2;
X		SqEr = (Y2 + Half) + (Half - X2);
X		if (SqEr < MinSqEr) MinSqEr = SqEr;
X		SqEr = Y2 - X2;
X		if (SqEr > MaxSqEr) MaxSqEr = SqEr;
X		}
X	}
X
/* IsYeqX */
X
IsYeqX()
{
X	if (Y != X) {
X		if (N <= 0) {
X			if (Z == Zero && Q <= Zero)
X				printf("WARNING:  computing\n");
X			else BadCond(Defect, "computing\n");
X			printf("\t(%.17e) ^ (%.17e)\n", Z, Q);
X			printf("\tyielded %.17e;\n", Y);
X			printf("\twhich compared unequal to correct %.17e ;\n",
X				X);
X			printf("\t\tthey differ by %.17e .\n", Y - X);
X			}
X		N = N + 1; /* ... count discrepancies. */
X		}
X	}
X
/* SR3980 */
X
SR3980()
{
X	do {
X		Q = (FLOAT) I;
X		Y = POW(Z, Q);
X		IsYeqX();
X		if (++I > M) break;
X		X = Z * X;
X		} while ( X < W );
X	}
X
/* PrintIfNPositive */
X
PrintIfNPositive()
{
X	if (N > 0) printf("Similar discrepancies have occurred %d times.\n", N);
X	}
X
/* TstPtUf */
X
TstPtUf()
{
X	N = 0;
X	if (Z != Zero) {
X		printf("Since comparison denies Z = 0, evaluating ");
X		printf("(Z + Z) / Z should be safe.\n");
X		sigsave = sigfpe;
X		if (setjmp(ovfl_buf)) goto very_serious;
X		Q9 = (Z + Z) / Z;
X		printf("What the machine gets for (Z + Z) / Z is  %.17e .\n",
X			Q9);
X		if (FABS(Q9 - Two) < Radix * U2) {
X			printf("This is O.K., provided Over/Underflow");
X			printf(" has NOT just been signaled.\n");
X			}
X		else {
X			if ((Q9 < One) || (Q9 > Two)) {
very_serious:
X				N = 1;
X				ErrCnt [Serious] = ErrCnt [Serious] + 1;
X				printf("This is a VERY SERIOUS DEFECT!\n");
X				}
X			else {
X				N = 1;
X				ErrCnt [Defect] = ErrCnt [Defect] + 1;
X				printf("This is a DEFECT!\n");
X				}
X			}
X		sigsave = 0;
X		V9 = Z * One;
X		Random1 = V9;
X		V9 = One * Z;
X		Random2 = V9;
X		V9 = Z / One;
X		if ((Z == Random1) && (Z == Random2) && (Z == V9)) {
X			if (N > 0) Pause();
X			}
X		else {
X			N = 1;
X			BadCond(Defect, "What prints as Z = ");
X			printf("%.17e\n\tcompares different from  ", Z);
X			if (Z != Random1) printf("Z * 1 = %.17e ", Random1);
X			if (! ((Z == Random2)
X				|| (Random2 == Random1)))
X				printf("1 * Z == %g\n", Random2);
X			if (! (Z == V9)) printf("Z / 1 = %.17e\n", V9);
X			if (Random2 != Random1) {
X				ErrCnt [Defect] = ErrCnt [Defect] + 1;
X				BadCond(Defect, "Multiplication does not commute!\n");
X				printf("\tComparison alleges that 1 * Z = %.17e\n",
X					Random2);
X				printf("\tdiffers from Z * 1 = %.17e\n", Random1);
X				}
X			Pause();
X			}
X		}
X	}
X
notify(s)
char *s;
{
X	printf("%s test appears to be inconsistent...\n", s);
X	printf("   PLEASE NOTIFY KARPINKSI!\n");
X	}
X
/*SPLIT msgs.c */
X
/* Instructions */
X
msglist(s)
char **s;
{ while(*s) printf("%s\n", *s++); }
X
Instructions()
{
X  static char *instr[] = {
X	"Lest this program stop prematurely, i.e. before displaying\n",
X	"    `END OF TEST',\n",
X	"try to persuade the computer NOT to terminate execution when an",
X	"error like Over/Underflow or Division by Zero occurs, but rather",
X	"to persevere with a surrogate value after, perhaps, displaying some",
X	"warning.  If persuasion avails naught, don't despair but run this",
X	"program anyway to see how many milestones it passes, and then",
X	"amend it to make further progress.\n",
X	"Answer questions with Y, y, N or n (unless otherwise indicated).\n",
X	0};
X
X	msglist(instr);
X	}
X
/* Heading */
X
Heading()
{
X  static char *head[] = {
X	"Users are invited to help debug and augment this program so it will",
X	"cope with unanticipated and newly uncovered arithmetic pathologies.\n",
X	"Please send suggestions and interesting results to",
X	"\tRichard Karpinski",
X	"\tComputer Center U-76",
X	"\tUniversity of California",
X	"\tSan Francisco, CA 94143-0704, USA\n",
X	"In doing so, please include the following information:",
#ifdef Single
X	"\tPrecision:\tsingle;",
#else
X	"\tPrecision:\tdouble;",
#endif
X	"\tVersion:\t10 February 1989;",
X	"\tComputer:\n",
X	"\tCompiler:\n",
X	"\tOptimization level:\n",
X	"\tOther relevant compiler options:",
X	0};
X
X	msglist(head);
X	}
X
/* Characteristics */
X
Characteristics()
{
X	static char *chars[] = {
X	 "Running this program should reveal these characteristics:",
X	"     Radix = 1, 2, 4, 8, 10, 16, 100, 256 ...",
X	"     Precision = number of significant digits carried.",
X	"     U2 = Radix/Radix^Precision = One Ulp",
X	"\t(OneUlpnit in the Last Place) of 1.000xxx .",
X	"     U1 = 1/Radix^Precision = One Ulp of numbers a little less than 1.0 .",
X	"     Adequacy of guard digits for Mult., Div. and Subt.",
X	"     Whether arithmetic is chopped, correctly rounded, or something else",
X	"\tfor Mult., Div., Add/Subt. and Sqrt.",
X	"     Whether a Sticky Bit used correctly for rounding.",
X	"     UnderflowThreshold = an underflow threshold.",
X	"     E0 and PseudoZero tell whether underflow is abrupt, gradual, or fuzzy.",
X	"     V = an overflow threshold, roughly.",
X	"     V0  tells, roughly, whether  Infinity  is represented.",
X	"     Comparisions are checked for consistency with subtraction",
X	"\tand for contamination with pseudo-zeros.",
X	"     Sqrt is tested.  Y^X is not tested.",
X	"     Extra-precise subexpressions are revealed but NOT YET tested.",
X	"     Decimal-Binary conversion is NOT YET tested for accuracy.",
X	0};
X
X	msglist(chars);
X	}
X
History()
X
{ /* History */
X /* Converted from Brian Wichmann's Pascal version to C by Thos Sumner,
X	with further massaging by David M. Gay. */
X
X  static char *hist[] = {
X	"The program attempts to discriminate among",
X	"   FLAWs, like lack of a sticky bit,",
X	"   Serious DEFECTs, like lack of a guard digit, and",
X	"   FAILUREs, like 2+2 == 5 .",
X	"Failures may confound subsequent diagnoses.\n",
X	"The diagnostic capabilities of this program go beyond an earlier",
X	"program called `MACHAR', which can be found at the end of the",
X	"book  `Software Manual for the Elementary Functions' (1980) by",
X	"W. J. Cody and W. Waite. Although both programs try to discover",
X	"the Radix, Precision and range (over/underflow thresholds)",
X	"of the arithmetic, this program tries to cope with a wider variety",
X	"of pathologies, and to say how well the arithmetic is implemented.",
X	"\nThe program is based upon a conventional radix representation for",
X	"floating-point numbers, but also allows logarithmic encoding",
X	"as used by certain early WANG machines.\n",
X	"BASIC version of this program (C) 1983 by Prof. W. M. Kahan;",
X	"see source comments for more history.",
X	0};
X
X	msglist(hist);
X	}
SHAR_EOF
chmod 0644 paranoia.c ||
echo 'restore of paranoia.c failed'
Wc_c="`wc -c < 'paranoia.c'`"
test 57545 -eq "$Wc_c" ||
	echo 'paranoia.c: original size 57545, current size' "$Wc_c"
fi
true || echo 'restore of pow.s failed'
echo End of part 3, continue with part 4
exit 0
--
Glenn Geers                       | "So when it's over, we're back to people.
Department of Theoretical Physics |  Just to prove that human touch can have
The University of Sydney          |  no equal."
Sydney NSW 2006 Australia         |  - Basia Trzetrzelewska, 'Prime Time TV'



More information about the Alt.sources mailing list