From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: David Kastrup <dak@gnu.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] diff: round down similarity index
Date: Mon, 25 Jun 2007 12:34:24 +0200 [thread overview]
Message-ID: <467F9A30.7040201@lsrfire.ath.cx> (raw)
In-Reply-To: <86k5tsh761.fsf@lola.quinscape.zz>
David Kastrup schrieb:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> 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.
Good idea! *smacks himself against the forehead*
I just copied the old code (sans the addition of 0.5) and then tried
to work around it's rounding problem (which I'm not even certain
exists and matters). Look out for an updated patch..
> You bet me to it on the way to work. Anyway, when working with
> integers, the first two lines are definitely not required (I am
> assuming that p->score is integer as well but have not checked).
Right.
> What probably requires more thought is the calculation of p->score
> itself: if one has large numbers as a ratio (original vs changes
> lines), multiplying by 60000 before dividing by the second large
> numbers might exceed the size of the integers.
MAX_SCORE is defined as 60000.0, which makes it a double. AFAICS all
the multiplications with MAX_SCORE are done using floating point
arithmetic for that reason.
René
next prev parent reply other threads:[~2007-06-25 10:34 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
[not found] ` <86k5tsh761.fsf@lola.quinscape.zz>
2007-06-25 10:34 ` René Scharfe [this message]
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=467F9A30.7040201@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=Johannes.Schindelin@gmx.de \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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).