bug-gzip
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: Removing -Wunsuffixed-float-constants, -Wdouble-promotion, -Wformat-zero-length
Date: Tue, 29 Nov 2011 15:31:30 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0

On 11/29/2011 03:23 PM, Jim Meyering wrote:
>>> @@ -238,7 +238,7 @@ hash_print_statistics (const Hash_table *table, FILE 
>>> *stream)
>>>    fprintf (stream, "# buckets:         %lu\n", (unsigned long int) 
>>> n_buckets);
>>>    fprintf (stream, "# buckets used:    %lu (%.2f%%)\n",
>>>             (unsigned long int) n_buckets_used,
>>> -           (100.0 * n_buckets_used) / n_buckets);
>>> +           (100.0F * n_buckets_used) / n_buckets);
>>
>> but this does not (in var-args, float gets promoted to double, so you
>> probably aren't gaining anything by using 'float' as an intermediary,
>> and starting with '100.0' as double is better to begin with).
> 
> Actually, 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.
> 

You missed my point - the compiler is going to be converting float to
double to pass the argument to fprintf, and fprintf will be operating on
double (%f and %lf both mean double on printf; they only differ on float
vs. double when dealing with scanf).  I see your point about the
possibility of the intermediate division in float possibly being faster,
but no matter how we look at things, the end result is still fprintf
operating on double, not float, whether or not we cared about the extra
precision.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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