home *** CD-ROM | disk | FTP | other *** search
/ PC-Test Pro / PCTESTPRO.iso / benchmrk / pentium / p4 / entp / fdv.c next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  5.0 KB  |  157 lines

  1. /****************************************************************************
  2.  -- PC Week Labs Float Divide Verification Test Suite (c)PC Week, 1994
  3.  -- Program FDV.EXE
  4.  --
  5.  -- This program attempts to verify IBM's reported Pentium error rates
  6.  -- in floating-point divisions using ratios of small decimal values
  7.  --
  8.  -- Program exhaustively tests all n.m cases not requiring a division by zero
  9.  -- and not (trivially) using a zero in a numerator
  10.  --
  11.  -- Test designed by Peter Coffee, PC Week Labs
  12.  -- Translated to C from the original Ada by Eamonn Sullivan, PC Week Labs
  13.  --
  14.  -- Suite may be freely distributed but may not be sold
  15.  -- Attributions may not be removed from source code or output
  16.  
  17. ------------------------------------------------------------------------------
  18. Compatibility Notes
  19.  
  20. When using the Visual C++ 1.51 compiler under Windows 3.x, you must add the
  21. /Op ("improve float consistency" in the Project settings) option when
  22. compiling the "release" version.  VC++ appears to silently reduce precision
  23. when "Full Optimization" is turned on.
  24.  
  25. The Watcom C/C++ compiler was also tested with all optimizations disabled
  26. due to similar observed effects with its default optimizations. PC Week Labs has attempted to determine the best possible combination of optimizations that
  27. does not suppress some known errors.
  28.  
  29. We have tested this code with the following compilers and operating systems:
  30.  
  31.  -- GNU C++ under SunOS 4.1.3 (on a Sparcstation) and under Linux
  32.  -- Watcom C386 9.0 and Microsoft Visual C++ 1.50 and 1.51 under DOS 6.2
  33.  -- Hewlett-Packard's C compiler under HP/UX (on a PA720 processor)
  34.  -- Watcom C/C++ 10.0 under OS/2 2.1
  35.  
  36. ------------------------------------------------------------------------------
  37. */
  38.  
  39.  
  40. #include <stdio.h>
  41. #include <math.h>
  42.  
  43. /* variables to test well-known ratio revealing Pentium bug */
  44.  
  45. double TestNum, TestDen, TestVal;
  46.  
  47. /* variables to test financial problem in IBM Pentium Study */
  48.  
  49. double YearsPerMonth, TaxRate, Tax, TakeHome, JobYears, PerAnnum;
  50.  
  51. /* variables to generate and test small decimal quotients */
  52.  
  53. double Num1, Num2, Den1, Quo1, Den2, Quo2, Dif;
  54. unsigned long Trials = 0;
  55. unsigned long Errors = 0;
  56.  
  57. /* loop counters for quotient components */
  58.  
  59. int i, j, k, l;
  60.  
  61. /* declaration for error threshold (added in C, not needed in Ada) */
  62.  
  63. double LSBError;
  64.  
  65. /****************************************************************************/
  66.  
  67. void main()
  68.  
  69. {
  70.  
  71. printf("PC Week Labs Float Divide Verification Suite (c)PC Week, 1994\n\n");
  72.  
  73. /*
  74.  -----------------------------------------------------------------------------
  75.  
  76.   -- Brief verification that we're on a buggy chip:
  77.   -- Set up for well-known calculation that shows an error in the
  78.   -- fifteenth bit of the binary result
  79.  
  80.  -----------------------------------------------------------------------------
  81. */
  82.  
  83. TestNum= (double) 4195835.0;
  84. TestDen= (double) 3145727.0;
  85.  
  86. printf("On accurate machines, the following is 0:           %g\n\n",
  87.                                  ((TestNum/TestDen)*TestDen - TestNum));
  88.  
  89. /*
  90.  -----------------------------------------------------------------------------
  91.  
  92.   -- Set up to verify IBM example:
  93.   -- The next six values verify the IBM report's example
  94.   -- of non-trivial errors in a realistic financial calculation
  95.  
  96.  -----------------------------------------------------------------------------
  97. */
  98.  
  99. YearsPerMonth = 0.083333333;
  100. TaxRate       = 0.1466667;
  101. Tax           = 96000.0 * TaxRate;
  102. TakeHome      = 96000.0 - Tax;
  103. JobYears      = 22.5 * YearsPerMonth;
  104. PerAnnum      = TakeHome / JobYears;
  105.  
  106. printf("On accurate machines, the following is 43,690.6651: %.4f\n\n",
  107.                                                            PerAnnum);
  108.  
  109. /* define tolerable least-significant-bit error */
  110.  
  111. LSBError = pow(2,-46);
  112.  
  113. printf("Suppressing errors of magnitude not greater than %8.5e\n\n",LSBError);
  114. printf("Testing quotients of form (a/b)/(c/d): a,b,c,d in [0.1,9.9] by 0.1\n\n");
  115. printf("Value of \"a\" is printed when incremented as progress check\n\n");
  116. printf("Output format is \"error: a, b, c, d\"\n\n");
  117.  
  118. for(i = 1; i < 100; i++)
  119.  
  120.   {
  121.     Num1 = (double) (i/10.0);
  122.     printf("%.1f\n", Num1);              /* this tracks error-free regions */
  123.  
  124.     for (j=1; j < 100; j++)
  125.       {
  126.         Den1 = (double) (j / 10.0);
  127.         Quo1 = (double) Num1 / Den1;
  128.  
  129.         for(k=1; k < 100; k++)
  130.           {
  131.             Num2 = (double) (k / 10.0);
  132.  
  133.             for(l=1; l < 100; l++)
  134.               {
  135.                 Den2 = (double) (l / 10.0);
  136.                 Quo2 = (double) Num2/Den2;
  137.  
  138.                 Trials++;
  139.  
  140.                 Dif = ((Quo1 / Quo2) * Quo2) - Quo1;
  141.  
  142.                 if (fabs(Dif) > LSBError)
  143.                   {
  144.                     Errors++;
  145.                     printf("Error is %8.5e: %3.1f, %3.1f, %3.1f, %3.1f\n",
  146.                                       Dif,   Num1,  Den1,  Num2,  Den2);
  147.                   }
  148.               }
  149.           }
  150.       }
  151.   }
  152.  
  153. printf("%lu errors in %lu trials.\n", Errors, Trials);
  154.  
  155. }
  156.  
  157.