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

           Summary: feqrel for const values too
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2011-08-31 22:09:28 PDT ---
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;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to