[Issue 13548] New: wrong FP comparison
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Sep 27 16:17:22 PDT 2014
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 at puremagic.com
Reporter: ilyayaroshenko at 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));
}
----------------
--
More information about the Digitalmars-d-bugs
mailing list