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

Don Clugston dclugston at gmail.com
Tue Jul 16 00:12:21 PDT 2013


On 15 July 2013 18:50, Iain Buclaw <ibuclaw at ubuntu.com> wrote:

> On 15 July 2013 16:22, Don Clugston <dclugston at gmail.com> wrote:
> >
> >
> > On 15 July 2013 11:46, Iain Buclaw <ibuclaw at ubuntu.com> wrote:
> >>
> >> But for floor and ceil, at least one of the following must be
> >> available in CTFE to allow setting bits.
> >>
> >> ----
> >> // Cannot convert &real to ushort* at compile time
> >> real y = x;
> >> ushort* sh = cast(ushort*)&y;
> >
> >
> >
> > Yeah. The problem with this, is that what happens if somebody stores the
> > pointer? It introduces loads of special cases.
> >
> > The most minimal solution would be to explicitly allow:
> >
> > ushort e = *(cast ushort *)&y;
> > *(cast ushort *)&y = e;
> >
>
> Hmm, how about static arrays of the same size?  This is safer because
> of copy semantics (e is a copy of y).
>
> ushort[8] e = *cast(ushort[8]*)&y;
> y = *cast(real *)&e;
>

True. But I don't think you would ever write runtime code that way, it
seems quite unnatural since it is so slow.
Could certainly be done.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20130716/c24019e6/attachment.html>


More information about the dmd-internals mailing list