qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC PATCH v4 07/30] Add SIZE type to qdev properties


From: Eric Blake
Subject: Re: [Qemu-devel] [RFC PATCH v4 07/30] Add SIZE type to qdev properties
Date: Wed, 20 Mar 2013 08:24:24 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4

On 03/20/2013 12:06 AM, li guang wrote:

>> +    return snprintf(dest, len, "%0.03f%c", (double)*ptr/div, suffixes[i]);
>                                     ^^^^^^     ^^^^^^^^^^^^^^^  
>> +}
>> +
> 
> IMHO, you may need (double)(*ptr/div), for type cast is right
> associated.

No, the code as written is correct, and your proposal would be wrong.
As written, it is evaluated as:

((double)*ptr) / div

which promotes the division to floating point.  Your proposal would do
the division (*ptr/div) as an integral (truncating) division, and only
then cast the result to double.

-- 
Eric Blake   eblake redhat com    +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]