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.

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.

Maybe the right solution is some kind of hidden parameter mechanism....

Stewart.

Reply via email to