On Wed, 3 May 2000, Jeff Garzik wrote:
> "B. James Phillippe" wrote:
> >
> > Hello,
> >
> > I know this is not legal. However, I'm reviewing some kernel module code
> > which basically does:
> >
> > unsigned long foo = some_other_ulong * 1.234;
>
> oof :) Reminds me of some fbdev code I saw a while back IIRC
>
> When you really want fractional numbers not literally floating point,
> you can always multiple both numbers to make them decimal, perform the
> math op, and then divide back down again.
>
> Jeff
>
Correct. In the cited case, the code could read:
foo = some_other_ulong * 1234 / 1000;
The complier sometimes optimizes the wrong stuff so 1234/1000 might
get optimized to 1 which is not what you want. Therefore, you can
force the issue by doing:
foo = some_other_ulong * 1234;
^__ sequence point
foo /= 1000;
Cheers,
Dick Johnson
Penguin : Linux version 2.3.41 on an i686 machine (800.63 BogoMips).
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:14 EST