Re: Irritation regarding precision of ping(8)...

From: Bruce Evans (bde_at_zeta.org.au)
Date: 10/31/04

  • Next message: Sean Chittenden: "Re: Irritation regarding precision of ping(8)..."
    Date: Sun, 31 Oct 2004 22:05:56 +1100 (EST)
    To: Sean Chittenden <sean@chittenden.org>
    
    

    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
    _______________________________________________
    freebsd-net@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-net
    To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"


  • Next message: Sean Chittenden: "Re: Irritation regarding precision of ping(8)..."

    Relevant Pages

    • Re: How to get number of digits in int variable?
      ... I know I don't have to explicitly set the field width with printf, ... Can anyone suggest how I might get the number of digits for a numeric ... I propose that fieldwidth is not calculated, but defined by the format. ...
      (comp.lang.c)
    • Re: ES format
      ... >> runtime format, even a runtime format that is trivially constant, not. ... You aren't allowed by Standard C to define any _external_ linkage ... In particular you certainly can define a 'static' function printf(), ... but otherwise it is part of the language and the compiler ...
      (comp.lang.fortran)
    • Re: vscanf and vprintf
      ... They take a pointer to a list of arguments rather than the arguments ... How can I write a function that takes a format string and a variable ... number of arguments, like printf, and passes them to printf to do most ... variable-length argument list, they accept a single va_list pointer. ...
      (comp.lang.c)
    • Re: how does printf handle an unknown number of arguments
      ... When you include stdio.h, you include a prototype for printfthat, ... int printf; ... The method printf() uses is a format string, which has embedded within it, ...
      (comp.lang.c)
    • Re: Custom date format not working in ACC2003
      ... It forces the year to display as 4 digits in dates, ... setting the Format of the control won't rescue it. ... the date fields in reports always format ...
      (microsoft.public.access.reports)