[uClibc] Re: Is there a workaround for this floating point bug?
David Wuertele
dave-gnus at bfnet.com
Mon Aug 11 03:10:42 UTC 2003
I have a new test program, its purpose is to avoid the whole printf()
issue I demonstrated before, which really isn't my main concern. My
main concern is that when using -msoft-float the floats' values appear
to be gone. Zero. No action.
Do you have time to try this version out on your soft-float mipsel
platform? Many thanks!
The program:
/** smath.cpp **/
#include <stdio.h>
#include <math.h>
/* shift the double val left then convert to integer before printing */
/* this gives us three decimal digits of precision without printing a float */
#define iprint(name,dval) do { \
fprintf (stderr, "%s = %lf; ", name, dval); \
double my_dval_e3 = dval * (double) 1000; \
int my_dval_i = (int) my_dval_e3; \
fprintf (stderr, "(int)(%s*e3) = %d\n", name, my_dval_i);\
} while (false)
int
main ()
{
int ia = 1, ib = 5, ic = 31, id = 41, ie = 47;
double difference = ia - ib; iprint("difference", difference);
double ratio = difference / ic; iprint("ratio", ratio);
double sum = ratio + id; iprint("sum", sum);
double product = sum * ie; iprint("product", product);
return 0;
}
I compile it three different ways:
$ gcc -o smath-gcc smath.cpp -lm
$ mipsel-uclibc-gcc -msoft-float -o smath-mgcc-softfloat smath.cpp -lm
$ mipsel-uclibc-gcc -save-temps -o smath-mgcc-kernelemu smath.cpp -lm
Execution on stock RH9 looks fine:
$ ./smath-gcc-kernelemu
difference = -4.000000; (int)(difference*e3) = -4000
ratio = -0.129032; (int)(ratio*e3) = -129
sum = 40.870968; (int)(sum*e3) = 40870
product = 1920.935484; (int)(product*e3) = 1920935
Execution of kernel emulated version on mipsel/uclibc-0.9.20 looks fine:
/ # ./smath-mgcc-kernelemu
difference = nan; (int)(difference*e3) = -4000
ratio = nan; (int)(ratio*e3) = -129
sum = nan; (int)(sum*e3) = 40870
product = nan; (int)(product*e3) = 1920935
Execution of -msoft-float version on mipsel/uclibc-0.9.20 is bogus:
/ # ./smath-mgcc-softfloat
difference = nan; (int)(difference*e3) = 0
ratio = nan; (int)(ratio*e3) = 0
sum = nan; (int)(sum*e3) = 0
product = nan; (int)(product*e3) = 0
/ #
Floats are all zero! Should I be taking this to some other list?
Any recommendations?
Dave
More information about the uClibc
mailing list