# HG changeset patch # User Christian Kamm # Date 1217273867 -7200 # Node ID 1c65b5477eaa27135c5560563934157796fe700d # Parent 491264b7cb93bd36c1a8f56590470a2becc1e173 Fix real comparison for real: allow +0 to be distinguished from -0. diff -r 491264b7cb93 -r 1c65b5477eaa dmd/expression.c --- a/dmd/expression.c Mon Jul 28 20:50:41 2008 +0200 +++ b/dmd/expression.c Mon Jul 28 21:37:47 2008 +0200 @@ -1494,11 +1494,12 @@ int RealEquals(real_t x1, real_t x2) { - return (isnan(x1) && isnan(x2)) || - /* In some cases, the REALPAD bytes get garbage in them, - * so be sure and ignore them. - */ - x1 == x2; + return // special case nans + (isnan(x1) && isnan(x2)) || + // and zero, in order to distinguish +0 from -0 + (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) || + // otherwise just compare + (x1 != 0. && x1 == x2); } int RealExp::equals(Object *o)