Mercurial > projects > ldc
comparison dmd/expression.c @ 421:1c65b5477eaa
Fix real comparison for real: allow +0 to be distinguished from -0.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Mon, 28 Jul 2008 21:37:47 +0200 |
parents | 491264b7cb93 |
children | 45a67b6f1310 |
comparison
equal
deleted
inserted
replaced
420:491264b7cb93 | 421:1c65b5477eaa |
---|---|
1492 * Regard +0 and -0 as different. | 1492 * Regard +0 and -0 as different. |
1493 */ | 1493 */ |
1494 | 1494 |
1495 int RealEquals(real_t x1, real_t x2) | 1495 int RealEquals(real_t x1, real_t x2) |
1496 { | 1496 { |
1497 return (isnan(x1) && isnan(x2)) || | 1497 return // special case nans |
1498 /* In some cases, the REALPAD bytes get garbage in them, | 1498 (isnan(x1) && isnan(x2)) || |
1499 * so be sure and ignore them. | 1499 // and zero, in order to distinguish +0 from -0 |
1500 */ | 1500 (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) || |
1501 x1 == x2; | 1501 // otherwise just compare |
1502 (x1 != 0. && x1 == x2); | |
1502 } | 1503 } |
1503 | 1504 |
1504 int RealExp::equals(Object *o) | 1505 int RealExp::equals(Object *o) |
1505 { RealExp *ne; | 1506 { RealExp *ne; |
1506 | 1507 |