Re: Floating point in kernel

From: Jeremy Fitzhardinge (jeremy@goop.org)
Date: Thu May 04 2000 - 17:36:18 EST


On 04-May-2000 Richard B. Johnson wrote:
> 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;

You don't need a sequence point, because it's not an order of execution issue.
In C, * and / have the same precidence but are left-associtive, so "a * b / c"
is unambigiously parsed and evaluated as "(a * b) / c". You could explicitly
parenthesize if you were feeling paranoid, but you'd still have to worry about
overflow.

        J

-
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:16 EST