Floating point problem on glibc-2.1.1
Ulrich Drepper
drepper@cygnus.com
Mon May 3 08:41:00 GMT 1999
Tung-Han Hsieh <thhsieh@linux.org.tw> writes:
> We discover a floating point problem on glibc-2.1.1:
>
> #include <math.h>
> #include <stdio.h>
>
> main()
> {
> printf("%d\n", (int)(log(8.0)/log(2.0)));
> }
The problem is in you code. What do expect other than an unreliable
result? All implementations have some error and if it is (in this
case) the case that the error struck at the wrong point you get
surprising results. If you would use
printf("%ld\n", round(log(8.0)/lrint(2.0)));
instead you'd get the expected result.
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com `------------------------
More information about the Libc-alpha
mailing list