Nmap Development mailing list archives
Re: Rounding of OS match percentages differs between architectures
From: "Michael Pattrick" <mpattrick () rhinovirus org>
Date: Wed, 19 Nov 2008 21:35:12 -0500
On Wed, Nov 19, 2008 at 8:26 PM, David Fifield <david () bamsoftware com> wrote:
On Wed, Nov 19, 2008 at 07:54:14PM -0500, Michael Pattrick wrote:On Wed, Nov 19, 2008 at 6:32 PM, David Fifield <david () bamsoftware com> wrote:Nmap currently uses printf("%d%%", (int) (frac * 100)) to show match percentages. Using printf("%.f%%", frac * 100) would remove this problem but would create another, namely that everything 99.5% and above would be rounded to 100%. Anyone have an opinion on this or see a good way to handle it?If I understand the problem properly - you want to strip the decimals, why not just use floor()?Hey, thanks, that works! I guess I assumed that ((int) d) and floor(d) would have the same result when d is positive. Apparently floor has extra logic to know when its argument is less than but very close to an integer. (To see what I mean by "very close to," run python and type in "0.98". I see "0.97999999999999998" as output.) I wonder if this is really caused by the C library? Can anyone else reproduce the "97% 98%" output from the test program I posted?
I got the same results as you testing on my 64 and 32bit Linux computers. I'm no expert but I would assume the the problem is an unhappy combination of a bug in libc and floating point inaccuracies. Consider the following #include <iostream> using namespace std; int main(){ for(float i=1.01;i<=5.05;i=i+1.01){ cout << i << ", "; } cout << endl; } outputs "1.01, 2.02, 3.03, 4.04," _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Rounding of OS match percentages differs between architectures David Fifield (Nov 19)
- Message not available
- Re: Rounding of OS match percentages differs between architectures David Fifield (Nov 19)
- Re: Rounding of OS match percentages differs between architectures jah (Nov 19)
- Re: Rounding of OS match percentages differs between architectures Brandon Enright (Nov 19)
- Re: Rounding of OS match percentages differs between architectures Brandon Enright (Nov 19)
- Re: Rounding of OS match percentages differs between architectures sara fink (Nov 23)
- Re: Rounding of OS match percentages differs between architectures Toni Ruottu (Nov 24)
- Re: Rounding of OS match percentages differs between architectures David Fifield (Nov 19)
- Message not available
- Re: Rounding of OS match percentages differs between architectures DePriest, Jason R. (Nov 19)
- Re: Rounding of OS match percentages differs between architectures Michael Pattrick (Nov 19)
- Re: Rounding of OS match percentages differs between architectures David Fifield (Nov 20)