[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing -Wunsuffixed-float-constants, -Wdouble-promotion, -Wformat-

From: Paul Eggert
Subject: Re: Removing -Wunsuffixed-float-constants, -Wdouble-promotion, -Wformat-zero-length
Date: Tue, 29 Nov 2011 16:34:53 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0

On 11/29/11 14:23, Jim Meyering wrote:
> if we cared about avoiding the warning, F would be fine there,
> since it's printing to a mere %.2f format.  We certainly don't need all
> of double's precision or exponent range for that.

For that app you're right, accuracy doesn't matter.
But in general I avoid 'float' for stuff like that.
E.g., if n_buckets_used is 1326 and n_buckets is 1583,

   printf ("%.2f", (100.0F * n_buckets_used) / n_buckets);

outputs the wrong answer, whereas omitting the F causes
it to output the right answer (this is on x86-64 compiled
with gcc 4.6.2 -O2).  Also, the code with 'float' is
slightly bigger and presumably a bit slower (this is
a common phenomenon on x86 and x86-64).

It's only the last digit that's wrong, of course,
and the performance difference is tiny,
but it's frustrating that some developer went
to the work of putting in that F to make the answer
slightly slower and slightly wrong.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]