⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 paranoia.c

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 C
📖 第 1 页 / 共 5 页
字号:
        V = V + ((One - HInvrse) * U2) * Y;    }    printf ("Overflow threshold is V  = %.17e .\n", V);    if (I)        printf ("Overflow saturates at V0 = %.17e .\n", V0);    else        printf ("There is no saturation value because \the system traps on overflow.\n");    V9 = V * One;    printf ("No Overflow should be signaled for V * 1 = %.17e\n", V9);    V9 = V / One;    printf ("                           nor for V / 1 = %.17e .\n", V9);    printf ("Any overflow signal separating this * from the one\n");    printf ("above is a DEFECT.\n");    /*=============================================*/    Milestone = 170;    /*=============================================*/    if (!(-V < V && -V0 < V0 && -UfThold < V && UfThold < V)) {        BadCond (Failure, "Comparisons involving ");        printf ("+-%g, +-%g\nand +-%g are confused by Overflow.",            V, V0, UfThold);    }    /*=============================================*/    Milestone = 175;    /*=============================================*/    printf ("\n");    for (Indx = 1; Indx <= 3; ++Indx) {        switch (Indx) {        case 1:            Z = UfThold;            break;        case 2:            Z = E0;            break;        case 3:            Z = PseudoZero;            break;        }        if (Z != Zero) {            V9 = SQRT (Z);            Y = V9 * V9;            if (Y / (One - Radix * E9) < Z                || Y > (One + Radix * E9) * Z) {        /* dgh: + E9 --> * E9 */                if (V9 > U1)                    BadCond (Serious, "");                else                    BadCond (Defect, "");                printf ("Comparison alleges that what prints as Z = %.17e\n", Z);                printf (" is too far from sqrt(Z) ^ 2 = %.17e .\n", Y);            }        }    }    /*=============================================*/    Milestone = 180;    /*=============================================*/    for (Indx = 1; Indx <= 2; ++Indx) {        if (Indx == 1)            Z = V;        else            Z = V0;        V9 = SQRT (Z);        X = (One - Radix * E9) * V9;        V9 = V9 * X;        if (((V9 < (One - Two * Radix * E9) * Z) || (V9 > Z))) {            Y = V9;            if (X < WVar)                BadCond (Serious, "");            else                BadCond (Defect, "");            printf ("Comparison alleges that Z = %17e\n", Z);            printf (" is too far from sqrt(Z) ^ 2 (%.17e) .\n", Y);        }    }    /*=============================================*/    Milestone = 190;    /*=============================================*/    Pause ();    X = UfThold * V;    Y = Radix * Radix;    if (X * Y < One || X > Y) {        if (X * Y < U1 || X > Y / U1)            BadCond (Defect, "Badly");        else            BadCond (Flaw, "");        printf (" unbalanced range; UfThold * V = %.17e\n\t%s\n",            X, "is too far from 1.\n");    }    /*=============================================*/    Milestone = 200;    /*=============================================*/    for (Indx = 1; Indx <= 5; ++Indx) {        X = F9;        switch (Indx) {        case 2:            X = One + U2;            break;        case 3:            X = V;            break;        case 4:            X = UfThold;            break;        case 5:            X = Radix;        }        Y = X;        sigsave = _sigfpe;        if (setjmp (ovfl_buf))            printf ("  X / X  traps when X = %g\n", X);        else {            V9 = (Y / X - Half) - Half;            if (V9 == Zero)                continue;            if (V9 == -U1 && Indx < 5)                BadCond (Flaw, "");            else                BadCond (Serious, "");            printf ("  X / X differs from 1 when X = %.17e\n", X);            printf ("  instead, X / X - 1/2 - 1/2 = %.17e .\n", V9);        }        sigsave = 0;    }    /*=============================================*/    Milestone = 210;    /*=============================================*/    MyZero = Zero;    printf ("\n");    printf ("What message and/or values does Division by Zero produce?\n");#ifndef BATCHMODE    printf ("This can interupt your program.  You can ");    printf ("skip this part if you wish.\n");    printf ("Do you wish to compute 1 / 0? ");    fflush (stdout);    read (KEYBOARD, ch, 8);    if ((ch[0] == 'Y') || (ch[0] == 'y')) {#endif /* !BATCHMODE */        sigsave = _sigfpe;        printf ("    Trying to compute 1 / 0 produces ...");        if (!setjmp (ovfl_buf))            printf ("  %.7e .\n", One / MyZero);        sigsave = 0;#ifndef BATCHMODE    } else        printf ("O.K.\n");    printf ("\nDo you wish to compute 0 / 0? ");    fflush (stdout);    read (KEYBOARD, ch, 80);    if ((ch[0] == 'Y') || (ch[0] == 'y')) {#endif /* !BATCHMODE */        sigsave = _sigfpe;        printf ("\n    Trying to compute 0 / 0 produces ...");        if (!setjmp (ovfl_buf))            printf ("  %.7e .\n", Zero / MyZero);        sigsave = 0;#ifndef BATCHMODE    } else        printf ("O.K.\n");#endif /* !BATCHMODE */    /*=============================================*/    Milestone = 220;    /*=============================================*/    Pause ();    printf ("\n");    {        static char *msg[] =        {            "FAILUREs  encountered =",            "SERIOUS DEFECTs  discovered =",            "DEFECTs  discovered =",            "FLAWs  discovered ="};        int     i;        for (i = 0; i < 4; i++)            if (ErrCnt[i])                printf ("The number of  %-29s %d.\n",                    msg[i], ErrCnt[i]);    }    printf ("\n");    if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[Defect]            + ErrCnt[Flaw]) > 0) {        if ((ErrCnt[Failure] + ErrCnt[Serious] + ErrCnt[                    Defect] == 0) && (ErrCnt[Flaw] > 0)) {            printf ("The arithmetic diagnosed seems ");            printf ("Satisfactory though flawed.\n");        }        if ((ErrCnt[Failure] + ErrCnt[Serious] == 0)            && (ErrCnt[Defect] > 0)) {            printf ("The arithmetic diagnosed may be Acceptable\n");            printf ("despite inconvenient Defects.\n");        }        if ((ErrCnt[Failure] + ErrCnt[Serious]) > 0) {            printf ("The arithmetic diagnosed has ");            printf ("unacceptable Serious Defects.\n");        }        if (ErrCnt[Failure] > 0) {            printf ("Potentially fatal FAILURE may have spoiled this");            printf (" program's subsequent diagnoses.\n");        }    } else {        printf ("No failures, defects nor flaws have been discovered.\n");        if (!((RMult == Rounded) && (RDiv == Rounded)                && (RAddSub == Rounded) && (RSqrt == Rounded)))            printf ("The arithmetic diagnosed seems Satisfactory.\n");        else {            if (StickyBit >= One &&                (Radix - Two) * (Radix - Nine - One) == Zero) {                printf ("Rounding appears to conform to ");                printf ("the proposed IEEE standard P");                if ((Radix == Two) &&                    ((Precision - Four * Three * Two) *                        (Precision - TwentySeven -                            TwentySeven + One) == Zero))                    printf ("754");                else                    printf ("854");                if (IEEE)                    printf (".\n");                else {                    printf (",\nexcept for possibly Double Rounding");                    printf (" during Gradual Underflow.\n");                }            }            printf ("The arithmetic diagnosed appears to be Excellent!\n");        }    }    if (fpecount)        printf ("\nA total of %d floating point exceptions were registered.\n",            fpecount);    printf ("END OF TEST.\n");    return 0;}FLOATSign (X)     FLOAT   X;{    return X >= 0. ? 1.0 : -1.0;}voidPause (){#ifndef BATCHMODE    char    ch[8];    printf ("\nTo continue, press RETURN");    fflush (stdout);    read (KEYBOARD, ch, 8);#endif /* !BATCHMODE */#ifndef CYGNUS    printf ("\nDiagnosis resumes after milestone Number %d", Milestone);    printf ("          Page: %d\n\n", PageNo);    ++Milestone;    ++PageNo;#endif /* !CYGNUS */}voidTstCond (K, Valid, T)     int     K, Valid;     char   *T;{#ifdef CYGNUS    printf ("TEST: %s\n", T);#endif /* CYGNUS */    if (!Valid) {        BadCond (K, T);        printf (".\n");    }#ifdef CYGNUS    printf ("PASS: %s\n", T);#endif /* CYGNUS */}voidBadCond (K, T)     int     K;     char   *T;{    static char *msg[] =    {"FAILURE", "SERIOUS DEFECT", "DEFECT", "FLAW"};    ErrCnt[K] = ErrCnt[K] + 1;#ifndef CYGNUS    printf ("%s:  %s", msg[K], T);#else    printf ("ERROR: Severity: %s:  %s", msg[K], T);#endif /* CYGNUS */}/* * Random computes *     X = (Random1 + Random9)^5 *     Random1 = X - FLOOR(X) + 0.000005 * X; *   and returns the new value of Random1*/FLOATRandom (){    FLOAT   X, Y;    X = Random1 + Random9;    Y = X * X;    Y = Y * Y;    X = X * Y;    Y = X - FLOOR (X);    Random1 = Y + X * 0.000005;    return (Random1);}voidSqXMinX (ErrKind)     int     ErrKind;{    FLOAT   XA, XB;    XB = X * BInvrse;    XA = X - XB;    SqEr = ((SQRT (X * X) - XB) - XA) / OneUlp;    if (SqEr != Zero) {        if (SqEr < MinSqEr)            MinSqEr = SqEr;        if (SqEr > MaxSqEr)            MaxSqEr = SqEr;        J = J + 1.0;        BadCond (ErrKind, "\n");        printf ("sqrt( %.17e) - %.17e  = %.17e\n", X * X, X, OneUlp * SqEr);        printf ("\tinstead of correct value 0 .\n");    }}voidNewD (){    X = Z1 * Q;    X = FLOOR (Half - X / Radix) * Radix + X;    Q = (Q - X * Z) / Radix + X * X * (D / Radix);    Z = Z - Two * X * D;    if (Z <= Zero) {        Z = -Z;        Z1 = -Z1;    }    D = Radix * D;}voidSR3750 (){    if (!((X - Radix < Z2 - Radix) || (X - Z2 > WVar - Z2))) {        I = I + 1;        X2 = SQRT (X * D);        Y2 = (X2 - Z2) - (Y - Z2);        X2 = X8 / (Y - Half);        X2 = X2 - Half * X2 * X2;        SqEr = (Y2 + Half) + (Half - X2);        if (SqEr < MinSqEr)            MinSqEr = SqEr;        SqEr = Y2 - X2;        if (SqEr > MaxSqEr)            MaxSqEr = SqEr;    }}voidIsYeqX (){    if (Y != X) {        if (N <= 0) {            if (Z == Zero && Q <= Zero)                printf ("WARNING:  computing\n");            else                BadCond (Defect, "computing\n");            printf ("\t(%.17e) ^ (%.17e)\n", Z, Q);            printf ("\tyielded %.17e;\n", Y);            printf ("\twhich compared unequal to correct %.17e ;\n",                X);            printf ("\t\tthey differ by %.17e .\n", Y - X);        }        N = N + 1;              /* ... count discrepancies. */    }}voidSR3980 (){    do {        Q = (FLOAT) I;        Y = POW (Z, Q);        IsYeqX ();        if (++I > M)            break;        X = Z * X;    }    while (X < WVar);}voidPrintIfNPositive (){    if (N > 0)        printf ("Similar discrepancies have occurred %d times.\n", N);}voidTstPtUf (){    N = 0;    if (Z != Zero) {        printf ("Since comparison denies Z = 0, evaluating ");        printf ("(Z + Z) / Z should be safe.\n");        sigsave = _sigfpe;        if (setjmp (ovfl_buf))            goto very_serious;        Q9 = (Z + Z) / Z;        printf ("What the machine gets for (Z + Z) / Z is  %.17e .\n",            Q9);        if (FABS (Q9 - Two) < Radix * U2) {            printf ("This is O.K., provided Over/Underflow");            printf (" has NOT just been signaled.\n");        } else {            if ((Q9 < One) || (Q9 > Two)) {              very_serious:         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -