Thread overview
[Issue 7691] New: A pure std.math.floor
Mar 28, 2012
Don
March 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7691

           Summary: A pure std.math.floor
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2012-03-11 14:12:35 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7691


hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx


--- Comment #1 from hsteoh@quickfur.ath.cx 2012-03-28 08:04:13 PDT ---
Most std.math functions need use asm; we need to write ctfe versions for them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7691



--- Comment #2 from bearophile_hugs@eml.cc 2012-03-28 10:03:17 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7691



--- Comment #3 from hsteoh@quickfur.ath.cx 2012-03-28 10:05:51 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 28, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7691


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2012-03-28 11:12:44 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------