Re: [PATCH] fix potential infinite loop given large unsigned integer
- From
Jeff Epler <jepler@unpythonic.net>
- Date
- Aug 11, 2009, 00:55 UTC
- Message-ID
- <20090811005517.GB32235@unpythonic.net>
- In-Reply-To
- <40aa078e0908090525h7b4d6efeh658e2edcfbe16c7e@mail.gmail.com>
On Sun, Aug 09, 2009 at 02:25:40PM +0200, Erik Faye-Lund wrote:
> log10() appears to be C99, but can be emulated on earlier C-versions by doing > #define log10(x) (log(x) / log(10.0))
I don't think you'll like the results of this very much.
#include <math.h>
#include <stdio.h> int main(void) {
double n=1;
int i, j;
for(i=0; i<10; i++, n*=10) {
j = (int)(log(n)/log(10));
if(i != j) printf("%d %d\n", i, (int)j);
}
return 0;
}(on my system, 3 of the 10 tested cases give the wrong answer due to rounding)
For a tour of some of the difficulties of implementing log10,
http://www.cs.berkeley.edu/~wkahan/LOG10HAF.TXTJeff