Skip to content

Commit

Permalink
POSIX: Use NV instead of hardcoded 'double' in strtol()/strtoul().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
t-a-k committed Aug 3, 2021
1 parent 0992730 commit fe27844
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/POSIX/POSIX.xs
Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit fe27844

Please sign in to comment.