Proposal: fixing the 'pure' floating point problem.
Michel Fortin
michel.fortin at michelf.com
Mon Mar 16 06:11:58 PDT 2009
On 2009-03-16 08:27:28 -0400, Don <nospam at nospam.com> said:
> That requires a new keyord, four new calling conventions, a new name
> mangling scheme, compiler insertion of special code, nasty issues with
> function pointers, ...
Which isn't much different as adding a new extern(x) option, for which
all these problems have been solved.
> for a feature that almost nobody will ever use. And it doesn't deal
> with dynamic rounding mode.
Well, isn't it dynamic rounding mode? I ask because you can change the
mode dynamically by calling a function. With floatmode(neutral) you
tell which function support any rounding mode, and with floatmode(x)
you choose which rounding mode to use within a function. It just makes
sure those changes are scoped and limit them to function boundaries.
If you want to evaluate the same function with two rounding modes, just
create a template:
R roundUp(alias a, R)(float arg) floatmode(round_up)
{
return a(arg);
}
R roundDown(alias a, R)(float arg) floatmode(round_down)
{
return a(arg);
}
then call it:
roundUp!(sin)(8);
roundDown!(sin)(8);
> And it doesn't solve the problem of the sticky flags.
As for sticky flags, couldn't they be returned by the template when you
care about them? Something like:
struct FloatAndStickyFlags {
this(float, int);
float value;
int sticky_flags;
}
FloatAndStickyFlags roundDownGetStickyFlags(alias a, R)(float arg)
floatmode(round_down)
{
return FloatAndStickyFlags(a(arg), getStickyFlags());
}
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list