summaryrefslogtreecommitdiff
path: root/dump.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2013-11-08 16:55:28 +0000
committerDavid Mitchell <davem@iabyn.com>2013-11-09 13:09:56 +0000
commitc279c4550ce59702722d0921739b1a1b92701b0d (patch)
tree24ee3a0f32ed60677664c7e43a5b3a52523948b8 /dump.c
parentb78a1974184592bd724e6c3f7a8b1e7d7aa63056 (diff)
downloadperl-c279c4550ce59702722d0921739b1a1b92701b0d.tar.gz
make perl core quiet under -Wfloat-equal
The gcc option -Wfloat-equal warns when two floating-point numbers are directly compared for equality or inequality, the idea being that this is usually a logic error, and that you should be checking that the values are instead very near to each other. perl on the other hand has lots of reasons to do a direct comparison. Add two macros, NV_eq_nowarn(a,b) and NV_eq_nowarn(a,b) that do the same as (a == b) and (a != b), but without the warnings. They achieve this by instead doing (a < b) || ( a > b). Under gcc at least, this is optimised into the same code as the direct comparison. The are three places that I've left untouched, because they are handling NaNs, and that gets a bit tricky. In particular (nv != nv) is a test for a NaN, and replacing it with (< || >) creates signalling NaNs (whereas == and != create quiet NaNs)
Diffstat (limited to 'dump.c')
-rw-r--r--dump.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/dump.c b/dump.c
index 409b975e7c..2ec4ebae06 100644
--- a/dump.c
+++ b/dump.c
@@ -475,7 +475,7 @@ Perl_sv_peek(pTHX_ SV *sv)
!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
SVp_POK|SVp_NOK)) &&
SvCUR(sv) == 0 &&
- SvNVX(sv) == 0.0)
+ NV_eq_nowarn(SvNVX(sv), 0.0))
goto finish;
}
else if (sv == &PL_sv_yes) {
@@ -486,7 +486,7 @@ Perl_sv_peek(pTHX_ SV *sv)
SVp_POK|SVp_NOK)) &&
SvCUR(sv) == 1 &&
SvPVX_const(sv) && *SvPVX_const(sv) == '1' &&
- SvNVX(sv) == 1.0)
+ NV_eq_nowarn(SvNVX(sv), 1.0))
goto finish;
}
else {