This is the mail archive of the
libc-alpha@cygnus.com
mailing list for the glibc project.
Re: Floating point problem on glibc-2.1.1
- To: Tung-Han Hsieh <thhsieh@linux.org.tw>
- Subject: Re: Floating point problem on glibc-2.1.1
- From: Ulrich Drepper <drepper@cygnus.com>
- Date: 03 May 1999 08:38:51 -0700
- Cc: libc-alpha@cygnus.com
- References: <19990503212712.A12774@tlug.sinica.edu.tw>
- Reply-To: drepper@cygnus.com (Ulrich Drepper)
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 `------------------------