All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Epler <jepler@unpythonic.net>
To: Erik Faye-Lund <kusmabite@googlemail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Ryan Flynn <parseerror@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] fix potential infinite loop given large unsigned integer
Date: Mon, 10 Aug 2009 19:55:17 -0500	[thread overview]
Message-ID: <20090811005517.GB32235@unpythonic.net> (raw)
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

  parent reply	other threads:[~2009-08-11  0:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-09  4:41 [PATCH] fix potential infinite loop given large unsigned integer Ryan Flynn
2009-08-09  6:19 ` Junio C Hamano
2009-08-09  7:38   ` Junio C Hamano
2009-08-09 12:25     ` Erik Faye-Lund
2009-08-10  5:24       ` Christian Couder
2009-08-10 11:12         ` Erik Faye-Lund
2009-08-10 12:24           ` Johannes Schindelin
2009-08-10 16:14             ` Ryan Flynn
2009-08-10 16:17             ` Ryan Flynn
2009-08-10 16:53               ` Johannes Schindelin
2009-08-11  0:55       ` Jeff Epler [this message]
2009-08-10  0:23     ` Ryan Flynn
2009-08-10 18:19     ` Tony Finch
2009-08-09 23:16   ` Ryan Flynn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090811005517.GB32235@unpythonic.net \
    --to=jepler@unpythonic.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kusmabite@googlemail.com \
    --cc=parseerror@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.