Re: On Arnold's challenge & Paul's Observation... - reordering
On Fri, Nov 28, 2008 at 2:23 PM, Ian McIntosh <ianm@xxxxxxxxxx> wrote:
>
> "Kreinovich, Vladik" <vladik@xxxxxxxx> wrote on 28/11/2008 11:34:24 AM:
>
>> ...
>> For example, as everyone know from numerical math, computing a+b+c also
>> depends on the order of the operations; some languages like C compute
>> left to right, Fortran if I remember correctly computes right to left,
>> and compilers change the order ...
>
> No, the C and Fortran standards both say the order of a+b+c is unspecified.
You are probably talking of the order of evaluation of operands (or arguments).
That is entirely different from the association of operands.
The C standard does specify that a+b+c associates to the left, e.g.
a+b+c is the same as (a+b)+c, and an implementation can rearrange
them *only if* it can prove that no overflow occurs and the result does
not change. See the extensive examples in the C99 standard
(paragraphs 13-15 in 5.1.2.3. This is not new. It is the
same rule as in C++ too.
> It may be evaluated as (a+b)+c or (b+c)+a or (a+c)+b. If you want a
No. See 5.1.2.3/13 of the C standard.
-- Gaby