[SeaBIOS] [Qemu-devel] [RFC PATCH v4 07/30] Add SIZE type to qdev properties
lig.fnst at cn.fujitsu.com
Thu Mar 21 01:39:48 CET 2013
在 2013-03-20三的 08:24 -0600，Eric Blake写道：
> 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.
Yes, you're right,
amazing c type cast!
More information about the SeaBIOS