From owner-freebsd-net@FreeBSD.ORG Sun Oct 31 11:06:14 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C6FDE16A4CE for ; Sun, 31 Oct 2004 11:06:14 +0000 (GMT) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id 237D343D1F for ; Sun, 31 Oct 2004 11:06:14 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])i9VB5xGx007421; Sun, 31 Oct 2004 22:05:59 +1100 Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) i9VB5uxc016348; Sun, 31 Oct 2004 22:05:57 +1100 Date: Sun, 31 Oct 2004 22:05:56 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Sean Chittenden In-Reply-To: Message-ID: <20041031214441.Q15594@delplex.bde.org> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-net@FreeBSD.org Subject: Re: Irritation regarding precision of ping(8)... X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Oct 2004 11:06:14 -0000 On Sun, 31 Oct 2004, Sean Chittenden wrote: > This has long bugged me and tonight I finally snapped and had to do > something about it. Example output: > > 64 bytes from a.b.c.d: icmp_seq=935 ttl=126 time=33.824 ms > 64 bytes from a.b.c.d: icmp_seq=936 ttl=126 time=29.138 ms > 64 bytes from a.b.c.d: icmp_seq=937 ttl=126 time=28.262 ms > 64 bytes from a.b.c.d: icmp_seq=938 ttl=126 time=29.67 ms > 64 bytes from a.b.c.d: icmp_seq=939 ttl=126 time=30.963 ms > 64 bytes from a.b.c.d: icmp_seq=940 ttl=126 time=30.283 ms > 64 bytes from a.b.c.d: icmp_seq=941 ttl=126 time=29.455 ms > > The source of irritation being line seq 930. The time should be 29.670 > since we are accurately measuring the precision to the thousands place. I think you mean line seq 938. This seems to be a local bug in printf. The correct format for printing 3 digits after the decimal point (%.3f) is already used, and printf of 29.67 with format %.3f gives 29.67 here. % Index: ping.c % =================================================================== % RCS file: /home/ncvs/src/sbin/ping/ping.c,v % retrieving revision 1.106 % diff -u -r1.106 ping.c % --- ping.c 30 Sep 2004 07:35:56 -0000 1.106 % +++ ping.c 31 Oct 2004 09:40:35 -0000 % @@ -998,7 +998,7 @@ % seq); % (void)printf(" ttl=%d", ip->ip_ttl); % if (timing) % - (void)printf(" time=%.3f ms", triptime); % + (void)printf(" time=%.30f ms", triptime); % if (dupflag) % (void)printf(" (DUP!)"); % if (options & F_AUDIBLE) %.30f is a horribly wrong format. It gives 30 digits after the decimal point, and inexact representation of 0.001 gives garbage nonzero digits for about half of the extra 27. % @@ -1293,7 +1293,7 @@ % double avg = tsum / n; % double vari = tsumsq / n - avg * avg; % (void)printf( % - "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n", % + "round-trip min/avg/max/stddev = %.30f/%.30f/%.30f/%.30f ms\n", % tmin, avg, tmax, sqrt(vari)); % } % This part also has some style bugs. Bruce