This is the mail archive of the libc-alpha@cygnus.com mailing list for the glibc project.


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

Re: Floating point problem on glibc-2.1.1


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   `------------------------


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