import std.math: floor; pure void main() { enum double x = floor(2.3); } DMD 2.059head gives: test.d(3): Error: pure function 'main' cannot call impure function 'floor' ...\dmd2\src\phobos\std\math.d(1917): Error: floorl cannot be interpreted at compile time, because it has no available source code test.d(3): called from here: floor(2.3L) So there are two problems here, floor is not pure and it can't run at compile-time. std.math.fmod() too isn't pure.
Most std.math functions need use asm; we need to write ctfe versions for them.
(In reply to comment #1) > Most std.math functions need use asm; we need to write ctfe versions for them. But note that I'd like to use it mostly in run-time code.
Does dmd even support pureness checking for asm blocks? If not, I'm not sure when we will be able to mark asm functions as pure.
(In reply to comment #3) > Does dmd even support pureness checking for asm blocks? If not, I'm not sure > when we will be able to mark asm functions as pure. asm blocks are ignored for pureness checking. And I think it has to be that way. In the asm for BigInt, at one point I write to a static variable. That variable is never read from, EVER. It's a trick to force Intel processors to stay in sync every pass through the loop. It would be impossible to enforce, anyway. BTW: floor() isn't pure, because floorl() isn't pure, because floorl(), being a C function, may set the matherr variable.
In dmd 2.066.1, I get: $ dmd test.d /usr/include/dmd/phobos/std/math.d(4183): Error: Cannot convert &double to ulong* at compile time /usr/include/dmd/phobos/std/math.d(3288): called from here: isNaN(x) test.d(4): called from here: floor(2.3) Any reason it has to be enum? Changing it to either const or immutable compiles fine: pure void main() { const double x = floor(2.3); }
(In reply to AndyC from comment #5) > Any reason it has to be enum? D needs to support basic operations like floor() at compile time too. I change the title of his issue.
std.math.floor is `pure` as of https://github.com/dlang/phobos/pull/1426 and currently works in CTFE.