www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5227] New: X ^^ FP at compile-time

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5227

           Summary: X ^^ FP at compile-time
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Currently this D2 code doesn't work:

import std.math;
enum x = 2 ^^ 3.5;
void main() {}


DMD 2.050 prints:

...\dmd\src\phobos\std\math.d(3214): Error: powl cannot be interpreted at
compile time, because it has no available source code
...\dmd\src\phobos\std\math.d(3217): Error: cannot evaluate impl(x,y) at
compile time
test.d(2): Error: cannot evaluate pow(2,3.5) at compile time
test.d(2): Error: cannot evaluate pow(2,3.5) at compile time


This limit may be removed using the ctfe_exp() and ctfe_log() functions of
Comment 6 here:
http://d.puremagic.com/issues/show_bug.cgi?id=3749#c6

Replacing this line 3214 of std.math.d:

        return core.stdc.math.powl(x, y);


With something like (not tested much):

        if (__ctfe)
        {
            return ctfe_exp(x * ctfe_log(b));
        }
        else
        {
            return core.stdc.math.powl(x, y);
        }



A small precision test, computing 2 ^^ 3.5:

core powl    = 11.313708498984761163
exp log CTFE = 11.313708498984760390

A more precise result with an algebra system shows that the CTFE version is the
more precise one of the two, it's correct to the last digit of the real number:

pow(2, 3.5) =  11.313708498984760390413509793677584628557375003015584...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5227


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg dawgfoto.de



There is missing CTFE support for some intrinsics.
Without exp and log family functions this can't be implemented.

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