Floating point performance issue
Tim Prince
n8tm@aol.com
Mon Dec 26 14:39:00 GMT 2011
On 12/26/2011 8:36 AM, Vincent Lefevre wrote:
> On 2011-12-26 08:22:11 -0500, Tim Prince wrote:
>> On 12/26/2011 7:59 AM, Vincent Lefevre wrote:
>>> On 2011-12-26 12:37:27 +0100, David Brown wrote:
>>>> If it matters that "a + b - c" be calculated "(a + b) - c" or "a + (b - c)",
>>>> then use brackets.
>>>
>>> but brackets shouldn't change anything with -fassociative-math.
>>>
>>> In C, brackets are purely syntactic, i.e. a + b - c is equivalent
>>> to (a + b) - c.
>> This was so prior to 1989, but the rules changed with the advent of ISO
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> standards. Even where compilers support algebraic simplification across
>> parentheses in violation of the standards, the results are unreliable as
>> well as non-portable.
>
> Wrong! The ISO C standard even gives an example (5.1.2.3p14) saying
> that an expression like a + b - c is equivalent to (a + b) - c.
>
True, in the case where left-to-right evaluation is not over-ruled by
parens. However, certain compilers which ignore parens also have no
reliable left-to-right or right-to-left evaluation rules.
--
Tim Prince
More information about the Gcc-help
mailing list