www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7996] New: Refuse std.math.isnan() on not floating point values?

http://d.puremagic.com/issues/show_bug.cgi?id=7996

           Summary: Refuse std.math.isnan() on not floating point values?
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



std.math.sqrt() refuses an argument of type long (despite this is handy):

import std.math;
void main() {
    long x;
    sqrt(x);
}



With (dmd 2.060alpha):

test.d(4): Error: function std.math.sqrt called with argument types:
    ((long))
matches both:
    std.math.sqrt(float x)
and:
    std.math.sqrt(real x)



While this compiles with no errors:

import std.math;
void main() {
    long x;
    assert(!isnan(x));
}


Maybe isnan() has to statically refuse arguments that aren't built-in floating
point (maybe with a std.traits.isFloatingPoint template constraint), this
avoids some bugs (I have had a bug caused by this).

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