Skip to content

Commit ce6f496

Browse files
sisyphuskhwilliamson
authored andcommitted
PATCH: [perl #41202] text->float gives wrong answer
This changes to use Perl_strtod() when available, and that turns out to be the key to fixing this bug. S_mulexp10() is removed from embed.fnc to avoid repeating the complicated prerequisites for defining Perl_strtod(). This works because this static function already was defined before use in numeric.c, and always called in full form without using a macro. James Keenan fixed a file permissions problem originally introduced by this commit, but the fix has been squashed into it.
1 parent c7ea9f0 commit ce6f496

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

embed.fnc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,12 +2879,6 @@ pn |Malloc_t |mem_log_realloc |const UV n|const UV typesize|NN const char *type_
28792879
pn |Malloc_t |mem_log_free |Malloc_t oldalloc|NN const char *filename|const int linenumber|NN const char *funcname
28802880
#endif
28812881

2882-
#if defined(PERL_IN_NUMERIC_C)
2883-
#ifndef USE_QUADMATH
2884-
sn |NV|mulexp10 |NV value|I32 exponent
2885-
#endif
2886-
#endif
2887-
28882882
#if defined(PERL_IN_UTF8_C)
28892883
sR |HV * |new_msg_hv |NN const char * const message \
28902884
|U32 categories \

embed.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,11 +1653,6 @@
16531653
#define utf16_textfilter(a,b,c) S_utf16_textfilter(aTHX_ a,b,c)
16541654
# endif
16551655
# endif
1656-
# if !defined(USE_QUADMATH)
1657-
# if defined(PERL_IN_NUMERIC_C)
1658-
#define mulexp10 S_mulexp10
1659-
# endif
1660-
# endif
16611656
# if !defined(UV_IS_QUAD)
16621657
# if defined(PERL_IN_UTF8_C)
16631658
#define is_utf8_cp_above_31_bits S_is_utf8_cp_above_31_bits

numeric.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ Perl_grok_atoUV(const char *pv, UV *valptr, const char** endptr)
11451145
return TRUE;
11461146
}
11471147

1148-
#ifndef USE_QUADMATH
1148+
#ifndef Perl_strtod
11491149
STATIC NV
11501150
S_mulexp10(NV value, I32 exponent)
11511151
{
@@ -1241,9 +1241,9 @@ S_mulexp10(NV value, I32 exponent)
12411241
}
12421242
return negative ? value / result : value * result;
12431243
}
1244-
#endif /* #ifndef USE_QUADMATH */
1244+
#endif /* #ifndef Perl_strtod */
12451245

1246-
#ifdef USE_QUADMATH
1246+
#ifdef Perl_strtod
12471247
# define ATOF(s, x) my_atof2(s, &x)
12481248
# else
12491249
# define ATOF(s, x) Perl_atof2(s, x)
@@ -1406,13 +1406,13 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, STRLEN len)
14061406
{
14071407
const char* s = orig;
14081408
NV result[3] = {0.0, 0.0, 0.0};
1409-
#if defined(USE_PERL_ATOF) || defined(USE_QUADMATH)
1409+
#if defined(USE_PERL_ATOF) || defined(Perl_strtod)
14101410
const char* send = s + ((len != 0)
14111411
? len
14121412
: strlen(orig)); /* one past the last */
14131413
bool negative = 0;
14141414
#endif
1415-
#if defined(USE_PERL_ATOF) && !defined(USE_QUADMATH)
1415+
#if defined(USE_PERL_ATOF) && !defined(Perl_strtod)
14161416
UV accumulator[2] = {0,0}; /* before/after dp */
14171417
bool seen_digit = 0;
14181418
I32 exp_adjust[2] = {0,0};
@@ -1425,7 +1425,7 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, STRLEN len)
14251425
I32 sig_digits = 0; /* noof significant digits seen so far */
14261426
#endif
14271427

1428-
#if defined(USE_PERL_ATOF) || defined(USE_QUADMATH)
1428+
#if defined(USE_PERL_ATOF) || defined(Perl_strtod)
14291429
PERL_ARGS_ASSERT_MY_ATOF3;
14301430

14311431
/* leading whitespace */
@@ -1442,7 +1442,7 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, STRLEN len)
14421442
}
14431443
#endif
14441444

1445-
#ifdef USE_QUADMATH
1445+
#ifdef Perl_strtod
14461446
{
14471447
char* endp;
14481448
char* copy = NULL;
@@ -1460,7 +1460,7 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, STRLEN len)
14601460
s = copy + (s - orig);
14611461
}
14621462

1463-
result[2] = strtoflt128(s, &endp);
1463+
result[2] = Perl_strtod(s, &endp);
14641464

14651465
/* If we created a copy, 'endp' is in terms of that. Convert back to
14661466
* the original */

proto.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,11 +4324,6 @@ STATIC void S_validate_suid(pTHX_ PerlIO *rsfp);
43244324
assert(rsfp)
43254325
# endif
43264326
#endif
4327-
#if !defined(USE_QUADMATH)
4328-
# if defined(PERL_IN_NUMERIC_C)
4329-
STATIC NV S_mulexp10(NV value, I32 exponent);
4330-
# endif
4331-
#endif
43324327
#if !defined(UV_IS_QUAD)
43334328
# if defined(PERL_IN_UTF8_C)
43344329
STATIC int S_is_utf8_cp_above_31_bits(const U8 * const s, const U8 * const e, const bool consider_overlongs)

0 commit comments

Comments
 (0)