www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2756] New: Bad code generation for pure nothrow math functions

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

           Summary: Bad code generation for pure nothrow math functions
           Product: D
           Version: 2.025
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au


Bad code generation occurs when the module is called 'std.math' in a module
statement, and the signature is exactly 'pure nothrow double XXX(double)' or
'pure nothrow float XXX(float)', and the parameter is a compile-time constant.
I suspect this is related to the special treatment of std.math.sqrt(), allowing
it to be evaluated at compile time.

----------------
MINIMAL TEST CASE:
----------------
module std.math;

pure nothrow double food(double x){ return 2.0;}

void main() {
       assert( food(1.0) == 2.0 );
}
----------------
FURTHER INFO:
----------------
module std.math;
import std.stdio;

pure nothrow float foof(float x){return 2.0;}
pure nothrow double food(double x){ return 2.0;}
pure nothrow real foor(real x) { return 2.0; }

void main() {
       writefln(foor(1.0)); // writes 2. OK.
       writefln(food(1.0)); // writes -0 !!
       writefln(foof(1.0)); // writes 0 !!
}


-- 
Mar 24 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2756


clugdbug yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch




------- Comment #1 from clugdbug yahoo.com.au  2009-03-24 05:36 -------
Patch:
builtin.c line 62
--------
                    if (ident == Id::_sqrt)  // add this line
                                builtin = BUILTINsqrt;
--------


-- 
Mar 24 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2756





------- Comment #2 from bugzilla digitalmars.com  2009-03-27 03:36 -------
Eh, that's an embarassing one!


-- 
Mar 27 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2756


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla digitalmars.com  2009-04-01 13:57 -------
Fixed DMD 2.027


-- 
Apr 01 2009