Function that calculates in compile time when it can
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Aug 6 08:54:29 PDT 2012
On Mon, Aug 6, 2012 at 5:33 PM, Minas Mina <minas_mina1990 at hotmail.co.uk> wrote:
> // calcuated at O(1) woohoo!
> return cast(ulong)(a * pow(r0, cast(double)n) + b * pow(r1,
I wonder if there is any rounding error going on with these pow, but
yes, even better this way.
> double f = sin(0.5); // calculated at compile time or not?
>
> If it is calculated at compile time, how do I do it for my own functions?
sin is a library function, it has no special rights your own function
doesn't as far as I know.
I'd say, put an if(__ctfe) in sin:
if (__ctfe)
{
pragma(msg, "Yep, CT");
return 2.0;
}
else
{
// standard sin code
}
And tell us the result :)
More information about the Digitalmars-d-learn
mailing list