import std.math: feqrel; void main() { double x = 1.5; const double y = 1.50000001; auto d = feqrel(x, y); } DMD 2.055head gives me: test.d(5): Error: template std.math.feqrel(X) if (isFloatingPoint!(X)) does not match any function template declaration test.d(5): Error: template std.math.feqrel(X) if (isFloatingPoint!(X)) cannot deduce template function from argument types !()(double,const(double)) I'd like feqrel to work with mixed const arguments too. Const doubles come from "in" function arguments, and they pop out in other situations too, like: import std.math: feqrel; double foo(double x) out(r) { assert(feqrel(r, x) > 10); } body { return x + 0.0000001; } void main() { foo(1.5); } Workaround: import std.math: feqrel; double foo(double x) out(r) { assert(feqrel(cast()r, x) > 10); } body { return x + 0.0000001; } void main() { foo(1.5); } To solve this problem I think that it's enough to replace this: int feqrel(X)(X x, X y) @trusted pure nothrow if (isFloatingPoint!(X)) { /* Public Domain. Author: Don Clugston, 18 Aug 2005. */ With something like: int feqrel(X1, X2)(X1 x, X2 y) @trusted pure nothrow if (isFloatingPoint!(Unqual!X1) && is(Unqual!X1 == Unqual!X2)) { /* Public Domain. Author: Don Clugston, 18 Aug 2005. */ alias Unqual!X1 X;
I hit this myself a couple of days ago. I prefer: int feqrel(X)(const(X) x, const(X) y) @trusted pure nothrow if (isFloatingPoint!(X)) which causes less template bloat, and also avoids some unpleasant issues where x and y are different sizes. I'm not really sure why double and const(double) need to be different types. It causes a huge amount of template bloat, and I don't think we're getting much (if anything) in return.
(In reply to comment #1) > I'm not really sure why double and const(double) need to be different types. It > causes a huge amount of template bloat, and I don't think we're getting much > (if anything) in return. Tell this again in the main D newsgroup :-)
Tested on git HEAD: the original code now compiles, although I did find a different related failing case: ======Code:====== import std.math, std.stdio; void main() { const(double) a=1.0, b=2.0; writeln(feqrel(a, b)); } ======Compile:====== /usr/src/d/phobos/std/math.d(5394): Error: cannot modify const expression diff test.d(4): Error: template instance std.math.feqrel!(const(double)) error instantiating
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/09ebc581ec022d0e1091d47887aab26366df79e0 rework and try to fix Issue 6586 https://github.com/D-Programming-Language/phobos/commit/62acd72cec052169e7eb56d1c63c860ae92f9ef9 Merge pull request #3017 from 9il/frexp [2.067.0-b2][regression] fix Issues 14212 and 6586
Commit pushed to 2.067 at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/cf57c7529a63ac970167c65cb659d5249a3a1ab9 Merge pull request #3017 from 9il/frexp [2.067.0-b2][regression] fix Issues 14212 and 6586
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/cf57c7529a63ac970167c65cb659d5249a3a1ab9 Merge pull request #3017 from 9il/frexp
Commits pushed to stable at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/09ebc581ec022d0e1091d47887aab26366df79e0 rework and try to fix Issue 6586 https://github.com/D-Programming-Language/phobos/commit/62acd72cec052169e7eb56d1c63c860ae92f9ef9 Merge pull request #3017 from 9il/frexp
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/09ebc581ec022d0e1091d47887aab26366df79e0 rework and try to fix Issue 6586 https://github.com/dlang/phobos/commit/62acd72cec052169e7eb56d1c63c860ae92f9ef9 Merge pull request #3017 from 9il/frexp