Floating point rounding modes: we should restrict them slightly

Michel Fortin michel.fortin at michelf.com
Sun Sep 13 03:54:47 PDT 2009


On 2009-09-13 06:14:02 -0400, Don <nospam at nospam.com> said:

> double foo() {
>    return x() + y();
> }
> x() and y() can use whichever rounding modes they like, and if they are 
> impure, they can affect one another, but under this proposal, they 
> cannot change the meaning of the addition inside foo().

Problems still may occur if x and y do memoization however. You call 
x() with one rounding mode, it memoize the results, then call x() with 
another rounding mode and it reuses the previous results while it 
shouldn't.

Basicaly, any memoization of x() should be discarded when you change 
the rounding mode. For instance the compiler should not reuse the value 
of x(), even if x is pure, in the following code:

	auto a = x();
	setRoundingMode(...);
	auto b = x();

Basically, setRoundingMode should act as some sort of barrier for the 
optimizer, but how?

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list