This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Wrong math results w/ Optim. [-O3 -mpentium]



  Kurt Garloff has reported serious errors with
  egcs-gcc/g++  -O3 -march=pentium.  My own test,
  based entirely on Kurts's work, may be of interest.
  (The entries in both columns should agree.)

  Using a very straight-forward, direct build of
  egcs-1.0.2, I find:

bash$ ./xgcc -o March-21 -B./ -O2 March-21.c -lm
bash$ ./March-21
 Gamma(1.0):  1.000000000e+00   1.000000000e+00
 Gamma(1.2):  9.181687424e-01   9.181687424e-01
 Gamma(1.4):  8.872638175e-01   8.872638175e-01
 Gamma(1.6):  8.935153493e-01   8.935153493e-01
 Gamma(1.8):  9.313837710e-01   9.313837710e-01
 Gamma(2.0):  1.000000000e+00   1.000000000e+00

bash$ ./xgcc -o March-21 -B./ -O2 -march=i486 March-21.c -lm
bash$ ./March-21
 Gamma(1.0):  1.000000000e+00   1.000000000e+00
 Gamma(1.2):  6.235220524e+00   9.181687424e-01
 Gamma(1.4):  6.038398579e+00   8.872638175e-01
 Gamma(1.6):  6.094059134e+00   8.935153493e-01
 Gamma(1.8):  6.365975172e+00   9.313837710e-01
 Gamma(2.0):  1.000000000e+00   1.000000000e+00

bash$ ./xgcc -o March-21 -B./ -O2 -march=i586 March-21.c -lm
bash$ ./March-21
 Gamma(1.0):  1.000000000e+00   1.000000000e+00
 Gamma(1.2):  1.234298459e-55   9.181687424e-01
 Gamma(1.4):  5.565679896e-56   8.872638175e-01
 Gamma(1.6):  2.613068522e-56   8.935153493e-01
 Gamma(1.8):  1.268755788e-56   9.313837710e-01
 Gamma(2.0):  1.000000000e+00   1.000000000e+00

bash$ ./xgcc -o March-21 -B./ -O2 -march=i686 March-21.c -lm
bash$ ./March-21
 Gamma(1.0):  1.000000000e+00   1.000000000e+00
 Gamma(1.2):  9.181687424e-01   9.181687424e-01
 Gamma(1.4):  8.872638175e-01   8.872638175e-01
 Gamma(1.6):  8.935153493e-01   8.935153493e-01
 Gamma(1.8):  9.313837710e-01   9.313837710e-01
 Gamma(2.0):  1.000000000e+00   1.000000000e+00

==================================================
==================================================
#include <math.h>

const double pi = 3.14159265358979323846264338328;
const double E1 = 2.71828182845904523536028747135;
const double cut_off = 46.0;


/* Stirling is only fine for large numbers */
double fact (double x)
{
    double corr, t;
   
    t = 1.0/x;
    corr = 1.0 + t*(1.0/12.0 + t*(1.0/288.0 - t*139.0/51840.0));

    return (pow(x/E1, x)*corr*sqrt(x*pi*2.0));
};

/* the gamma fct */
double gamma (double x)
{
    double res, x0;

    x0 = x-1;
    if (x0 > cut_off) return fact (x0);
    x0 += cut_off - floor(x0);
    res = fact (x0);
    while ((x-x0) < 0.5) { res /= x0; x0 -= 1.0; };
    return res;
};


int main ()
{
       printf(" Gamma(1.0): %16.9e  %16.9e\n", gamma(1.0), exp(lgamma(1.0)));
       printf(" Gamma(1.2): %16.9e  %16.9e\n", gamma(1.2), exp(lgamma(1.2)));
       printf(" Gamma(1.4): %16.9e  %16.9e\n", gamma(1.4), exp(lgamma(1.4)));
       printf(" Gamma(1.6): %16.9e  %16.9e\n", gamma(1.6), exp(lgamma(1.6)));
       printf(" Gamma(1.8): %16.9e  %16.9e\n", gamma(1.8), exp(lgamma(1.8)));
       printf(" Gamma(2.0): %16.9e  %16.9e\n", gamma(2.0), exp(lgamma(2.0)));
}


---------------------------------------------
bregor@anusf.anu.edu.au   +61 2 6249-2046   (02) 6249-2046
Date: 22-Mar-98            Time: 13:15:17

Australian National University Supercomputer Facility
=====================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]