From fe27844798d0a953ac84251ec7a02bcf6d5925bd Mon Sep 17 00:00:00 2001 From: TAKAI Kousuke <62541129+t-a-k@users.noreply.github.com> Date: Tue, 22 Jun 2021 23:54:00 +0900 Subject: [PATCH] POSIX: Use NV instead of hardcoded 'double' in strtol()/strtoul(). Casting (unsigned) long value to 'double' might cause unnecessary loss of precision if double's significand is not enough wide to preserve (unsigned) long and NV is configured to be wider than double. --- ext/POSIX/POSIX.xs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index be45ac6fb975..2c8529bc20f3 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -3549,7 +3549,7 @@ strtol(str, base = 0) num = strtol(str, &unparsed, base); #if IVSIZE < LONGSIZE if (num < IV_MIN || num > IV_MAX) - PUSHs(sv_2mortal(newSVnv((double)num))); + PUSHs(sv_2mortal(newSVnv((NV)num))); else #endif PUSHs(sv_2mortal(newSViv((IV)num))); @@ -3583,7 +3583,7 @@ strtoul(str, base = 0) num = strtoul(str, &unparsed, base); #if UVSIZE < LONGSIZE if (num > UV_MAX) - PUSHs(sv_2mortal(newSVnv((double)num))); + PUSHs(sv_2mortal(newSVnv((NV)num))); else #endif PUSHs(sv_2mortal(newSVuv((UV)num)));