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

Iain Buclaw ibuclaw at ubuntu.com
Tue Jul 16 02:55:48 PDT 2013


On 16 July 2013 08:12, Don Clugston <dclugston at gmail.com> wrote:
> 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.
>

I wouldn't have thought it would be much different to using a union.

--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the dmd-internals mailing list