On 2009-09-10 04:24:38 -0400, Don <[email protected]> said:
PROPOSAL:
Change the spec by adding the line to float.html:
"If the floating-point rounding mode is changed within a function, it
must be restored before the function exits. If this rule is violated
(for example, by the use of inline asm), the rounding mode used for
subsequent calculations is undefined."
This slight tightening of semantics can have a significant benefit for
all floating-point code.
I perfectly agree. I'm just wondering how to enforce it in the language.
Later in the thread you say:
... have an RAII struct to restore the mode automatically. But that's
just syntax sugar.
But how do you prevent someone from writing:
auto s = new roundingMode(...);
The only way you can really make sure it's scoped to a specific
function is to call it from another function:
R performWithRoundingMode(R)(flag roundingMode, lazy R result)
{
flag oldRoundingMode = getRoundingMode();
setRoundingMode(roundingMode);
try
return result;
finally
setRoundingMode(oldRoundingMode);
}
auto i = performWithRoundingMode(TOWARDS_ZERO, 12 * 12);
Here you can't escape the scoping requirements.
--
Michel Fortin
[email protected]
http://michelf.com/