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

           Summary: std.math.pow should be a template
           Product: D
           Version: 1.039
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: clugd...@yahoo.com.au
        ReportedBy: schvei...@yahoo.com


Currently, pow is an overloaded function, which always takes real as the first
argument.

However, real isn't a common variable type, so passing something that can be
implicitly casted to real results in a compiler overload resolution error.

This problem could be solved by implementing pow as a wrapper to the original
function (named e.g. _pow):

real pow(T, U)(T t, U u)
{
   return _pow(cast(real)t, u);
}

This should take care of cases where you try to pass a double, int, or even
possibly a custom struct that supports an opCast to real.

I'm not sure if casts are needed for the second argument, if they are, special
care should be taken to not cast integral types to real, as the integer
versions are optimized for that.


-- 

Reply via email to