OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.22/] [lcc/] [tst/] [paranoia.c] - Diff between revs 4 and 21

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.