digitalmars.D.learn - std.math.sqrt(real x) && std.math.sqrt(float x) overloads
- Tobias Pankrath (22/22) May 09 2012 Shouldn't this just work?
- bearophile (7/16) May 09 2012 In theory yes, in practice probably it's better for it to not
- Jonathan M Davis (6/33) May 09 2012 It's amibigous, so no it doesn't just work. There was a discussion in wh...
Shouldn't this just work?
--
struct Point
{
int x, y;
Point opBinary(string op)(Point rhs)
{
return mixin("Point(x " ~ op ~ " rhs.x, y " ~ op ~ "
rhs.y)");
}
}
double dist(Point a, Point b)
{
return sqrt(abs(a.x - b.x) ^^ 2 + abs(a.y - b.y) ^^ 2);
}
Instead it's
Error: function std.math.sqrt called with argument types:
((int))
matches both:
std.math.sqrt(float x)
and:
std.math.sqrt(real x)
May 09 2012
Tobias Pankrath:
Shouldn't this just work?
...
Instead it's
Error: function std.math.sqrt called with argument types:
((int))
matches both:
std.math.sqrt(float x)
and:
std.math.sqrt(real x)
In theory yes, in practice probably it's better for it to not
compile, given the current situation of the D type system.
Bye,
bearophile
(this is probably one of the less informative answers I've given
recently)
May 09 2012
On Wednesday, May 09, 2012 21:39:38 Tobias Pankrath wrote:
Shouldn't this just work?
--
struct Point
{
int x, y;
Point opBinary(string op)(Point rhs)
{
return mixin("Point(x " ~ op ~ " rhs.x, y " ~ op ~ "
rhs.y)");
}
}
double dist(Point a, Point b)
{
return sqrt(abs(a.x - b.x) ^^ 2 + abs(a.y - b.y) ^^ 2);
}
Instead it's
Error: function std.math.sqrt called with argument types:
((int))
matches both:
std.math.sqrt(float x)
and:
std.math.sqrt(real x)
It's amibigous, so no it doesn't just work. There was a discussion in what to
do about it a few months back. I don't remember all of the details, but you
can read it here:
http://forum.dlang.org/thread/j7mt9q$1tsa$1 digitalmars.com
- Jonathan M Davis
May 09 2012









"bearophile" <bearophileHUGS lycos.com> 