std.math.sqrt(real x) && std.math.sqrt(float x) overloads

Jonathan M Davis jmdavisProg at gmx.com
Wed May 9 13:29:55 PDT 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


More information about the Digitalmars-d-learn mailing list