[Issue 10763] (&x)[0 .. 1] doesn't work in CTFE
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 19 10:22:58 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10763
--- Comment #11 from Iain Buclaw <ibuclaw at ubuntu.com> 2013-08-19 10:22:55 PDT ---
(In reply to comment #10)
>
> So... this might be very well doable, but will have to be *extremely* careful
> about it. Also, I'm assuming that CTFE is able to get values from constant
> static arrays?
Adapted code so that it does the following:
real <-> ushort[8]:
RealExp <-> VectorExp(ushort[8]) <-> ArrayLiteralExp(ushort[8])
Result?
---
ushort[8] foo(real x)
{ return *cast(ushort[8]*)(&x);
}
real bar(ushort[8] x)
{ return *cast(real*)(&x);
}
pragma(msg, foo(42.0L));
pragma(msg, bar(foo(42.0L)));
static assert(foo(42.0L) == [0,0,0,43008,16388,0,0,0]);
static assert(bar(foo(42.0L)) == 42.0L);
pragma(msg, "Success!");
---
$ gdc -c paint.d
[cast(ushort)0u, cast(ushort)0u, cast(ushort)0u, cast(ushort)43008u,
cast(ushort)16388u, cast(ushort)0u, cast(ushort)0u, cast(ushort)0u]
4.2e+1
Success!
Only downside is that it is restricted to T[x].sizeof == real.sizeof.
So real<->ulong[2] only works with 128bit reals on 64bit, but could look into
getting around that later...
Don, I think I'm ready to test trial this in GDC if you are willing to
implement this in DMD?
Regards
Iain.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list