[Issue 2636] New: std.math.pow should be a template
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 30 06:54:17 PST 2009
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: clugdbug at yahoo.com.au
ReportedBy: schveiguy at 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.
--
More information about the Digitalmars-d-bugs
mailing list