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

Iain Buclaw ibuclaw at ubuntu.com
Mon Jul 15 09:50:46 PDT 2013


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;


--
Iain Buclaw

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


More information about the dmd-internals mailing list