Counter-proposal: Syntax for FP Attributes on blocks or expressions

Joel C. Salomon joelcsalomon at gmail.com
Fri Mar 13 09:06:24 PDT 2009


Don wrote:
> Consider this code:
> double add(double x, double y) {
>     return x + y;
> }
> Is this code pure? (…)
> Technically, it isn't. If you change the floating-point rounding mode on
> the processor, you get a different result for exactly the same inputs.

IEEE 754-2008, §4 (Attributes and Rounding), prescribes:
	An attribute is logically associated with a program block to
	modify its numerical and exception semantics. A user can specify
	a constant value for an attribute parameter.

	Some attributes have the effect of an implicit parameter to most
	individual operations of this standard; language standards shall
	specify
		— rounding-direction attributes (see 4.3)
	and should specify
		— alternate exception handling attributes (see 8).

If D offered some way to statically set these attributes on a block to
anything but the default, this could make the code pure. (Unless you
explicitly set the mode to “dynamic”, as normally is the case on x86.)

More likely, though, you’d want to template code like this on the
currently-selected rounding mode.

So, can D become the first language to properly implement this aspect of
754-2008?

—Joel Salomon



More information about the Digitalmars-d mailing list