Function that calculates in compile time when it can

Eyyub eyyub.pangearaion at gmail.com
Mon Aug 6 09:21:04 PDT 2012


On Monday, 6 August 2012 at 16:17:22 UTC, Minas Mina wrote:
> On Monday, 6 August 2012 at 15:56:52 UTC, Namespace wrote:
>> Take a look into std.math:
>> https://github.com/D-Programming-Language/phobos/blob/master/std/math.d
>
> I found this:
>
> real sin(real x) @safe pure nothrow; /* intrinsic */
>
> And these:
>
> creal sin(creal z) @safe pure nothrow
> {
>      creal cs = expi(z.re);
>      creal csh = coshisinh(z.im);
>      return cs.im * csh.re + cs.re * csh.im * 1i;
> }
>
> /** ditto */
> ireal sin(ireal y) @safe pure nothrow
> {
>      return cosh(y.im)*1i;
> }
>
> I don't see anything about ctfe. Maybe I didn't understand well
> and sin is not evaluated at compile time. Can someone clarify
> this?

Justly, you see a normal runtime function, and a CTFE function is
a normal runtime function(with some restrictions) that can be
interpreted at runtime.

static res = sin(4); //compile time
auto res = sin(4); //runtime


More information about the Digitalmars-d-learn mailing list