On Thursday, 27 March 2014 at 18:18:25 UTC, H. S. Teoh wrote:
Some time ago, Iain Buclaw kindly added non-asm implementations of math functions in std.math. However, CTFE still seems unable to correctly
evaluate certain functions like atan2:

        import std.math;
        enum x = atan2(1.0, 2.0);

Compiler output:

/usr/src/d/phobos/std/math.d(856): Error: asm statements cannot be interpreted at compile time /usr/src/d/phobos/std/math.d(917): called from here: atan2(cast(real)y, cast(real)x)
        test.d(2):        called from here: atan2(1.00000, 2.00000)

Looking at std/math.d, it appears that version=InlineAsm_X86_Any is defined, which leads to the asm implementation of atan2, which CTFE
can't interpret.

However, right below that block is an else block containing a D
implementation of atan2 that AFAICT *can* be interpreted in CTFE.

So it would appear that version=InlineAsm_X86_Any should be suppressed during CTFE? But I'm not sure how this could be done in the compiler.

In any case, it's an annoying limitation. :-(


T

//----
auto atan(double x)
{
    version(InlineAsm_X86_Any)
    if (!__ctfe)
    {
        asm
        {
            ...
        }
        return;
    }

    Fall back non-InlineAsm_X86_Any and ctfe
}
//----

?

Reply via email to