From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: David Kastrup <dak@gnu.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] diff: round down similarity index
Date: Sun, 24 Jun 2007 23:18:33 -0700 [thread overview]
Message-ID: <7vir9co8ue.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <467EEEE6.3090100@lsrfire.ath.cx> (René Scharfe's message of "Mon, 25 Jun 2007 00:23:34 +0200")
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> +static int similarity_index(struct diff_filepair *p)
> +{
> + int result = p->score * 100.0 / MAX_SCORE;
> +
> + /* Paranoia: guard against floating point rounding errors. */
> + if (p->score == MAX_SCORE)
> + result = 100;
> + else if (result == 100)
> + result = 99;
> +
> + return result;
> +}
Why not simply do this?
static int similarity_index(struct diff_filepair *p)
{
if (p->score == MAX_SCORE)
return 100;
return p->score * 100 / MAX_SCORE;
}
MAX_SCORE and p->score run up to 60000 and we assume int is at
least 32-bit, so I do not think there is no risk of overflowing.
next prev parent reply other threads:[~2007-06-25 6:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-24 22:23 [PATCH] diff: round down similarity index René Scharfe
2007-06-24 23:25 ` Johannes Schindelin
2007-06-24 23:27 ` Johannes Schindelin
2007-06-25 1:29 ` René Scharfe
2007-06-25 5:08 ` David Kastrup
2007-06-25 6:18 ` Junio C Hamano [this message]
[not found] ` <86k5tsh761.fsf@lola.quinscape.zz>
2007-06-25 10:34 ` René Scharfe
2007-06-25 10:34 ` [PATCH] diff: round down similarity index, take 2 René Scharfe
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=7vir9co8ue.fsf@assigned-by-dhcp.cox.net \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=rene.scharfe@lsrfire.ath.cx \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).