On Tue, Jan 06, 2015 at 10:44:38AM -0800, Walter Bright via Digitalmars-d wrote:
> On 1/6/2015 10:07 AM, H. S. Teoh via Digitalmars-d wrote:
> >Implementing union painting in CTFE would singlehandedly solve
> >(almost?) all of std.math CTFE issues, AFAICT.
> 
> I thought it did allow painting of the form *(cast(T*)&t).

Was that a recent addition? I don't remember that working last year.

In any case, the current std.math code tries to achieve repainting via
unions, which currently doesn't work in CTFE:

        ulong ctfeFunc(double d) {
                union U {
                        double f;
                        ulong  ul;
                }
                U u;
                u.f = d;
                return u.ul;    // <--- CTFE error
        }
        enum x = ctfeFunc(3.141592);


Maybe I remembered wrong, but the original std.math code relied on
*(cast(T*)&t) to work, but was rewritten to use union repainting, IIRC
because union painting is considered more likely to be implemented in
CTFE (? -- my guess; I could be wrong).

In any case, it's great news that repainting is now supported in CTFE.
Hopefully this means more of std.math will be usable at compile-time
soon!


T

-- 
"The whole problem with the world is that fools and fanatics are always so 
certain of themselves, but wiser people so full of doubts." -- Bertrand 
Russell. "How come he didn't put 'I think' at the end of it?" -- Anonymous

Reply via email to