Floating point rounding modes: we should restrict them slightly

Rainer Deyke rainerd at eldwood.com
Mon Sep 14 20:32:34 PDT 2009


Don wrote:
> Rainer Deyke wrote:
>> Don't forget that "uses floating point" is a transitive property.  Any
>> pure function that calls a pure-but-unmemoisable function is itself
>> pure-but-unmemoisable.
> 
> This is incorrect.

Then I must have misunderstood your proposal.  Either you did a poor job
of explaining it, or I did a poor job of trying to understand it, or
it's not as simple as you make it out to be.

Since I'm not really interested in discussing the details of floating
point rounding modes and memoisation, I'll just leave it at that.

>> Is there any real need to treat floating point state differently from
>> other global state in regard to "pure"?
> 
> Yes. Because it's all-pervasive.

It only affects floating point operations.  Other pieces of global state
(e.g. the global locale) affect other operations.  Once you make a
special case for floating point mode, it's easy to argue that the
special case should be extended to other pieces of global data.  A
general solution generally beats special cases.

Or maybe I'm completely overthinking this.

> Unless you treat it specially, you
> cannot use floating point in any pure function. That creates a
> restriction which is so severe that 'pure' becomes useless. Something
> like the following template function could not be pure:
> 
> T add(T a, T b) { return a + b; }

In the presence of structs and class executing arbitrary code in opPlus,
you can't make this pure anyway.  Unless you force opPlus itself to be
pure, which is almost certainly too restrictive for the current
definition of pure.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list