[Issue 5227] New: X ^^ FP at compile-time
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 16 18:48:17 PST 2010
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 at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2010-11-16 18:47:03 PST ---
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: -------
More information about the Digitalmars-d-bugs
mailing list