Stewart Gordon wrote:
Don wrote:
<snip>
LISTING ONE:
real x = foo(1) + foo(2) + foo(3);
LISTING TWO:
real x1 = foo(1);
real x2 = foo(2);
real x3 = foo(3);
real x = x1 + x2 + x3;
In C and C++ (and currently in D), they are NOT equivalent!
foo() is allowed to change the floating-point rounding mode, so it
could change the meaning of '+'.
<snip>
This is just one aspect of it. You could also call a pure function,
change the rounding mode, and then call the pure function again on the
same arguments. The value returned would change, thereby violating the
purity.
I already presented a proposal for that. This proposal is primarily for
functions which are not pure.
There has been some talk about pure functions in relation to locales:
http://d.puremagic.com/issues/show_bug.cgi?id=3057
http://www.digitalmars.com/d/archives/digitalmars/D/std.locale_85081.html
Floating point settings are just another case of the same thing, except
that currently violations in relation to the former are allowed.
There's a fundamental difference between them: the floating point
settings are a hardware feature and it is IMPOSSIBLE to avoid them. You
can choose not to use locale settings. Or, you can pass them as a
parameter, which doesn't work for floating point settings.
Please do not get sidetracked on pure functions, it is orthogonal to
this issue.