[dmd-internals] Pure CTFE-able std.math

Don Clugston dclugston at gmail.com
Tue Jul 16 00:08:56 PDT 2013


On 15 July 2013 16:54, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:

> On Tue, Jul 16, 2013 at 12:04:08AM +1000, Daniel Murphy wrote:
> > I would prefer to see (as either builtins or properties) a way to
> > get/set the exponent/mantissa/sign of a float.
> >
> > eg
> > float x;
> > x.sign = 1;
> > assert(x.exp == 123);
> >
> > Easily ctfeable, no need for casting, no endianness problems.
> [...]
>
> +1. IMO this is the right way to handle floating-point attributes.
> Direct knowledge about the binary representation should be restricted to
> the compiler as much as possible. Plus, having these attributes could
> potentially be useful in other contexts than std.math.
>

No. You shouldn't be doing these kind of operations in normal code, you
should be using normal arithmetic. If you need to know the exponent, you
should use library functions like frexp().
You shouldn't be poking in the internals of a float unless you know the bit
pattern exactly, and you need the extra speed.
This issue only applies to 80-bit reals on x86, this is really a very
special case. Floats and doubles already allow the necessary casts.







>
>
> T
>
> --
> The best way to destroy a cause is to defend it poorly.
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20130716/462d5370/attachment.html>


More information about the dmd-internals mailing list