Re: Floating point in kernel

From: Jamie Lokier (
Date: Thu May 04 2000 - 15:06:11 EST

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;

Assuming some_other_ulong is an integral type (e.g. unsigned long :-),
the compiler will always evaluate this from left to right -- you do not
have to force the issue. The compiler is permitted to reorder such
things as (integral) "a + b - c" because the result is the same, on a
machine where integers simply wrap.

You may be thinking of floating point operations. Some compilers do
like to mess with the order of floating operations on the the grounds
that the result is arithmetically equivalent. But floating point values
aren't real numbers and so sometimes you do need to force the issue with
a sequence point.

have a nice day,
-- Jamie

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:15 EST