c99 fmin fmax wankers

Compile this with pgcc 6.1-5 64-bit target on x86-64 Linux

pgcc -c9x test.c

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main(void) {
        double k =0.0e0, l=100.0e0;
        double mx = fmax(k,l);
        double mn = fmin(k,l);

        printf("%15.6E\n",fmin(k,l));
        printf("%15.6f\n",mn);
        printf("%15.6f\n",mx);
        printf("%15.6E\n",fmax(k,l));

        return 0;
}

Output is:

6.953356E-310
2.000000
2.000000
2.000000E+00

Hi Steve,

The fmax and fmin prototypes in the Linux math header files are guarded by GNU define flags so the correct definition are not being used. To correct, you’ll need to add the prototypes to your code.

% cat test.c
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

double fmax(double, double);
double fmin(double, double);

int main(void) {
        double k =0.0e0, l=100.0e0;
        double mx = fmax(k,l);
        double mn = fmin(k,l);

        printf("%15.6E\n",fmin(k,l));
        printf("%15.6f\n",mn);
        printf("%15.6f\n",mx);
        printf("%15.6E\n",fmax(k,l));

        return 0;
}

% pgcc -V6.1 -c9x test.c
% a.out
   0.000000E+00
       0.000000
     100.000000
   1.000000E+02

I’ve added a technical problem report (TPR#3892) to have this corrected in a future release.

Thanks,
Mat