Wireshark-bugs: [Wireshark-bugs] [Bug 6527] corba dissector generator improvement
Date: Tue, 1 Nov 2011 21:05:25 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6527

Guy Harris <guy@xxxxxxxxxxxx> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Attachment #7354|review_for_checkin?         |review_for_checkin-
               Flag|                            |

--- Comment #8 from Guy Harris <guy@xxxxxxxxxxxx> 2011-11-01 21:05:22 PDT ---
(From update of attachment 7354)
I'm still not sure I see the advantage of that over just using "%g":


$ cat float.c
#include <stdio.h>
#include <math.h>

static const float  FLT_DISPLAY = 1e9;
static const double DBL_DISPLAY = 1e12;

int
main(void)
{
    float f;
    double d;
    int i;

    f = 1.5e-8;
    d = 1.5e-8;
    for (i = -8; i < 15; i++) {
        printf("float: ");
        if (fabsf(f) > FLT_DISPLAY)
            printf("%.6g, ", f);
        else
            printf("%.6f, ", f);
        printf("%.6g, ", f);

        printf("double: ");
        if (fabsf(d) > DBL_DISPLAY)
            printf("%.15g: ", d);
        else
            printf("%.15f: ", d);
        printf("%.15g\n", d);

        f *= 10;
        d *= 10;
    }
    return 0;
}
$ gcc float.c
$ ./a.out
float: 0.000000, 1.5e-08, double: 0.000000015000000: 1.5e-08
float: 0.000000, 1.5e-07, double: 0.000000150000000: 1.5e-07
float: 0.000001, 1.5e-06, double: 0.000001500000000: 1.5e-06
float: 0.000015, 1.5e-05, double: 0.000015000000000: 1.5e-05
float: 0.000150, 0.00015, double: 0.000150000000000: 0.00015
float: 0.001500, 0.0015, double: 0.001500000000000: 0.0015
float: 0.015000, 0.015, double: 0.015000000000000: 0.015
float: 0.150000, 0.15, double: 0.150000000000000: 0.15
float: 1.500000, 1.5, double: 1.500000000000000: 1.5
float: 14.999999, 15, double: 15.000000000000000: 15
float: 149.999985, 150, double: 150.000000000000000: 150
float: 1499.999878, 1500, double: 1500.000000000000000: 1500
float: 14999.999023, 15000, double: 15000.000000000000000: 15000
float: 149999.984375, 150000, double: 150000.000000000000000: 150000
float: 1499999.875000, 1.5e+06, double: 1500000.000000000000000: 1500000
float: 14999999.000000, 1.5e+07, double: 15000000.000000000000000: 15000000
float: 149999984.000000, 1.5e+08, double: 150000000.000000000000000: 150000000
float: 1.5e+09, 1.5e+09, double: 1500000000.000000000000000: 1500000000
float: 1.5e+10, 1.5e+10, double: 15000000000.000000000000000: 15000000000
float: 1.5e+11, 1.5e+11, double: 150000000000.000000000000000: 150000000000
float: 1.5e+12, 1.5e+12, double: 1500000000000: 1500000000000
float: 1.5e+13, 1.5e+13, double: 15000000000000: 15000000000000
float: 1.5e+14, 1.5e+14, double: 150000000000000: 150000000000000

The only place where there might be an advantage is in the values where %g
rounds things off; in other places, you lose significant digits, or get extra
zeroes.

Elsewhere in Wireshark, we just use %.6g and %.15g (%.15g for a long time, %.6g
rather than %.6f since my recent checkin to epan/proto.c).  If for numbers with
positive exponents %f might be useful, but I'm not sure it has any advantage
for numbers with negative exponents.

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.