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

Re: [PATCH] diff: round down similarity index

From
David Kastrup <dak@gnu.org>
Date
Jun 25, 2007, 05:08 UTC
Message-ID
<85y7i8boyh.fsf@lola.goethe.zz>
In-Reply-To
<467EEEE6.3090100@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> +static int similarity_index(struct diff_filepair *p)
> +{
> +	int result = p->score * 100.0 / MAX_SCORE;

Use floor(p->score ... MAX_SCORE) here: I don't think that C otherwise specifies a preferred way of rounding on float->int conversions.

Show 5 quoted lines
> +	/* Paranoia: guard against floating point rounding errors. */
> +	if (p->score == MAX_SCORE)
> +		result = 100;
> +	else if (result == 100)
> +		result = 99;
Also, p->score itself must be calculated by truncating.
-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Previous: René ScharfeNext: Junio C Hamano
Message 5 of 8 in “diff: round down similarity index”
  1. diff: round down similarity indexRené Scharfe, Jun 24, 2007
  2. Johannes SchindelinJun 24, 2007
  3. Johannes SchindelinJun 24, 2007
  4. René ScharfeJun 25, 2007
  5. David KastrupJun 25, 2007
  6. Junio C HamanoJun 25, 2007
  7. diff: round down similarity index, take 2René Scharfe, Jun 25, 2007
  8. René ScharfeJun 25, 2007

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.