www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13548] New: wrong FP comparison

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

          Issue ID: 13548
           Summary: wrong FP comparison
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: ilyayaroshenko gmail.com

Win64 & FreeBSD32 are affected.
Tester:
https://auto-tester.puremagic.com/pull-history.ghtml?projectid=1&repoid=3&pullid=2548
PR:
https://github.com/D-Programming-Language/phobos/pull/2548#issuecomment-57064711

----------------
unittest
{
    import std.stdio;
    import std.string;
    assert(isIdentical(abs(-0.0L), 0.0L));
    assert(isNaN(abs(real.nan)));
    assert(abs(-real.infinity) == real.infinity);
    assert(abs(-3.2Li) == 3.2L);
    assert(abs(71.6Li) == 71.6L);
    assert(abs(-56) == 56);
    assert(abs(2321312L)  == 2321312L);
    assert(abs(creal  (-1+1i)) == sqrt(2.0L));
    cdouble c = -1+1i;
    assert(sqrt(c.re*c.re+c.im*c.im) == sqrt(2.0));
    double ad, bd, cd;
    ad = sqrt(2.0);
    bd = hypot(c.re, c.im);
    cd = sqrt(2.0);  
    assert(ad == cd, "FP fail"); //<-----------------------FAILS SQRT(2) !=
SQRT(2)
    assert(ad == bd, format("sqrt(2.0) = %.*a, hypot(c.re, c.im) = %.*a", 25,
ad, 25, bd));
    assert(hypot(c.re, c.im) == sqrt(2.0), format("sqrt(2.0) = %.*a,
hypot(c.re, c.im) = %.*a", 20, sqrt(2.0), 20, hypot(c.re, c.im)));
    assert(abs(c) == sqrt(2.0));
    assert(abs(cdouble(-1+1i)) == sqrt(2.0 ));
    assert(abs(cfloat (-1+1i)) == sqrt(2.0f));
}
----------------

--
Sep 27 2014