math.pow fails at compile-time; is this a bug?

Jonathan M Davis jmdavisProg at gmx.com
Sun Aug 19 21:43:01 PDT 2012


On Sunday, August 19, 2012 23:38:01 Caligo wrote:
> template T(){
>   enum a = pow(3.0, 2);
>   enum b = pow(3, 2.0);
> }
> 
> unittest
> {
>   alias T!() t;
> }
> 
> compiling that I get:
> 
> /home/b/phobos/std/math.d(2369): Error: Cannot convert &real to ushort* at
> compile time
> /home/b/phobos/std/math.d(3292):        called from here: isNaN(y)
> /home/b/phobos/std/math.d(3403):        called from here:
> impl(x,cast(real)y)
> /home/b/phobos/std/math.d(3239):        called from here: pow(cast(real)x,y)
> t.d(478):        called from here: pow(3,2)
> t.d(485): Error: template instance units.T!() error instantiating
> 
> I guess this a bug?  any workarounds?

Not all functions work at compile time. It's a valid enhancement request, but 
unless a function's documentation says that it works in CTFE, there's no 
guarantee that it does. However, we _do_ need to do a better job of marking 
functions for CTFE in their documentation and testing for it to make sure that 
they stay CTFEable. I have no clue what pow's state is, but it does look like 
it's not currently designed to work in CTFE.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list