[Issue 13474] DMD optimizer FP arithmetic bug

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Sep 15 10:52:16 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13474

--- Comment #3 from Илья Ярошенко <ilyayaroshenko at gmail.com> ---
Please Discard previous 2 comments.

//$ dmd -m32 -O -main -unittest -run test4.d
//core.exception.AssertError at test4.d(28): 0
import core.stdc.tgmath;
double sumKBN(Range)(Range r)
{
    double s = 0.0;
    double c = 0.0;
    foreach(double x; r)
    {
        double t = s + x;
        if(s.fabs >= x.fabs)
            c += (s-t)+x;
        else
            c += (x-t)+s;
        s = t;
    }

    return s + c;
}
unittest 
{
    import std.algorithm, std.range, std.conv;
    auto ar1 = [1, 1e100, 1, -1e100].map!(a => a*10000).array;
    auto ar2 = [1, 1e100, 1, -1e100].map!(a => a*10000);
    double r = 20000;
    assert(r == ar1.sumKBN);    // Ok
    assert(r == ar2.sumKBN, ar2.sumKBN.to!string);    // fails
}

--


More information about the Digitalmars-d-bugs mailing list