Thread (13 messages) flat view 13 messages, 7 authors, 2016-06-15

Re: [PATCH] fix potential infinite loop given large unsigned integer

From: Jeff Epler <hidden>
Date: 2016-06-15 22:47:13

Possibly related (same subject, not in this thread)

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.TXT

Jeff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help