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.