From: Junio C Hamano Date: Mon, 25 Jun 2007 06:18:33 GMT Subject: Re: [PATCH] diff: round down similarity index Message-ID: <7vir9co8ue.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <467EEEE6.3090100@lsrfire.ath.cx> René Scharfe 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.