From 427fbfe878efea40f50caa8b0da22803460f50b0 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 14 Dec 2016 14:24:08 +1100 Subject: (perl #130335) fix numeric comparison for sort's built-in compare For non-'use integer' this would always compare as NVs, but with 64-bit integers and non-long doubles, integers can have more significant digits, making the sort <=> replacement less precise than the <=> operator. Use the same code to perform the comparison that <=> does, which happens to be handily broken out into Perl_do_ncmp(). --- pp_sort.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'pp_sort.c') diff --git a/pp_sort.c b/pp_sort.c index 68e65f9f94..4ffe224842 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1888,20 +1888,16 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b) static I32 S_sv_ncmp(pTHX_ SV *const a, SV *const b) { - const NV nv1 = SvNSIV(a); - const NV nv2 = SvNSIV(b); + I32 cmp = do_ncmp(a, b); PERL_ARGS_ASSERT_SV_NCMP; -#if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan) - if (Perl_isnan(nv1) || Perl_isnan(nv2)) { -#else - if (nv1 != nv1 || nv2 != nv2) { -#endif + if (cmp == 2) { if (ckWARN(WARN_UNINITIALIZED)) report_uninit(NULL); return 0; } - return nv1 < nv2 ? -1 : nv1 > nv2 ? 1 : 0; + + return cmp; } static I32 -- cgit v1.2.1