|
|
734417 |
From 78787052b6a68c0f54cfa983a69c44276de9daa4 Mon Sep 17 00:00:00 2001
|
|
|
734417 |
From: Jesse Luehrs <doy@tozt.net>
|
|
|
734417 |
Date: Tue, 26 Jun 2012 00:13:54 -0500
|
|
|
734417 |
Subject: [PATCH] use a less broken test for locale radix in atof [perl #109318]
|
|
|
734417 |
|
|
|
734417 |
---
|
|
|
734417 |
lib/locale.t | 33 +++++++++++++++++++++++++++++++++
|
|
|
734417 |
numeric.c | 25 +++++++++++++++----------
|
|
|
734417 |
2 files changed, 48 insertions(+), 10 deletions(-)
|
|
|
734417 |
|
|
|
734417 |
diff --git a/lib/locale.t b/lib/locale.t
|
|
|
734417 |
index dfc6d2b..26a7bd4 100644
|
|
|
734417 |
--- a/lib/locale.t
|
|
|
734417 |
+++ b/lib/locale.t
|
|
|
734417 |
@@ -1247,6 +1247,39 @@ foreach $Locale (@Locale) {
|
|
|
734417 |
print "# failed $locales_test_number locale '$Locale' characters @f\n"
|
|
|
734417 |
}
|
|
|
734417 |
}
|
|
|
734417 |
+
|
|
|
734417 |
+ # [perl #109318]
|
|
|
734417 |
+ {
|
|
|
734417 |
+ my @f = ();
|
|
|
734417 |
+ ++$locales_test_number;
|
|
|
734417 |
+ $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
|
|
|
734417 |
+
|
|
|
734417 |
+ my $radix = POSIX::localeconv()->{decimal_point};
|
|
|
734417 |
+ my @nums = (
|
|
|
734417 |
+ "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
|
|
|
734417 |
+ "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
|
|
|
734417 |
+ );
|
|
|
734417 |
+
|
|
|
734417 |
+ if (! $is_utf8_locale) {
|
|
|
734417 |
+ use locale;
|
|
|
734417 |
+ for my $num (@nums) {
|
|
|
734417 |
+ push @f, $num
|
|
|
734417 |
+ unless sprintf("%g", $num) =~ /3.+14/;
|
|
|
734417 |
+ }
|
|
|
734417 |
+ }
|
|
|
734417 |
+ else {
|
|
|
734417 |
+ use locale ':not_characters';
|
|
|
734417 |
+ for my $num (@nums) {
|
|
|
734417 |
+ push @f, $num
|
|
|
734417 |
+ unless sprintf("%g", $num) =~ /3.+14/;
|
|
|
734417 |
+ }
|
|
|
734417 |
+ }
|
|
|
734417 |
+
|
|
|
734417 |
+ tryneoalpha($Locale, $locales_test_number, @f == 0);
|
|
|
734417 |
+ if (@f) {
|
|
|
734417 |
+ print "# failed $locales_test_number locale '$Locale' numbers @f\n"
|
|
|
734417 |
+ }
|
|
|
734417 |
+ }
|
|
|
734417 |
}
|
|
|
734417 |
|
|
|
734417 |
my $final_locales_test_number = $locales_test_number;
|
|
|
734417 |
diff --git a/numeric.c b/numeric.c
|
|
|
734417 |
index be86f3a..3eb8a0e 100644
|
|
|
734417 |
--- a/numeric.c
|
|
|
734417 |
+++ b/numeric.c
|
|
|
734417 |
@@ -847,17 +847,22 @@ Perl_my_atof(pTHX_ const char* s)
|
|
|
734417 |
|
|
|
734417 |
PERL_ARGS_ASSERT_MY_ATOF;
|
|
|
734417 |
|
|
|
734417 |
- if (PL_numeric_local && IN_SOME_LOCALE_FORM) {
|
|
|
734417 |
- NV y;
|
|
|
734417 |
+ if (PL_numeric_local && PL_numeric_radix_sv && IN_SOME_LOCALE_FORM) {
|
|
|
734417 |
+ char *standard = NULL, *local = NULL;
|
|
|
734417 |
+ bool use_standard_radix;
|
|
|
734417 |
|
|
|
734417 |
- /* Scan the number twice; once using locale and once without;
|
|
|
734417 |
- * choose the larger result (in absolute value). */
|
|
|
734417 |
- Perl_atof2(s, x);
|
|
|
734417 |
- SET_NUMERIC_STANDARD();
|
|
|
734417 |
- Perl_atof2(s, y);
|
|
|
734417 |
- SET_NUMERIC_LOCAL();
|
|
|
734417 |
- if ((y < 0.0 && y < x) || (y > 0.0 && y > x))
|
|
|
734417 |
- return y;
|
|
|
734417 |
+ standard = strchr(s, '.');
|
|
|
734417 |
+ local = strstr(s, SvPV_nolen(PL_numeric_radix_sv));
|
|
|
734417 |
+
|
|
|
734417 |
+ use_standard_radix = standard && (!local || standard < local);
|
|
|
734417 |
+
|
|
|
734417 |
+ if (use_standard_radix)
|
|
|
734417 |
+ SET_NUMERIC_STANDARD();
|
|
|
734417 |
+
|
|
|
734417 |
+ Perl_atof2(s, x);
|
|
|
734417 |
+
|
|
|
734417 |
+ if (use_standard_radix)
|
|
|
734417 |
+ SET_NUMERIC_LOCAL();
|
|
|
734417 |
}
|
|
|
734417 |
else
|
|
|
734417 |
Perl_atof2(s, x);
|
|
|
734417 |
--
|
|
|
734417 |
1.7.4.1
|
|
|
734417 |
|