git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.TXT
Jeff
Previous: Johannes SchindelinNext: Ryan Flynn
Message 11 of 14 in “fix potential infinite loop given large unsigned integer”
  1. fix potential infinite loop given large unsigned integerRyan Flynn, Aug 9, 2009
  2. Junio C HamanoAug 9, 2009
  3. Junio C HamanoAug 9, 2009
  4. Erik Faye-LundAug 9, 2009
  5. Christian CouderAug 10, 2009
  6. Erik Faye-LundAug 10, 2009
  7. Johannes SchindelinAug 10, 2009
  8. Ryan FlynnAug 10, 2009
  9. Ryan FlynnAug 10, 2009
  10. Johannes SchindelinAug 10, 2009
  11. Jeff EplerAug 11, 2009
  12. Ryan FlynnAug 10, 2009
  13. Tony FinchAug 10, 2009
  14. Ryan FlynnAug 9, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.