double num;
char *unparsed;
PPCODE:
- SET_NUMERIC_LOCAL();
+ STORE_NUMERIC_STANDARD_FORCE_LOCAL();
num = strtod(str, &unparsed);
PUSHs(sv_2mortal(newSVnv(num)));
if (GIMME == G_ARRAY) {
else
PUSHs(&PL_sv_undef);
}
+ RESTORE_NUMERIC_STANDARD();
void
strtol(str, base = 0)
bool was_standard = PL_numeric_standard && IN_SOME_LOCALE_FORM; \
if (was_standard) SET_NUMERIC_LOCAL();
+/* Rarely, we want to change to the underlying locale even outside of 'use
+ * locale'. This is principally in the POSIX:: functions */
+#define STORE_NUMERIC_STANDARD_FORCE_LOCAL() \
+ bool was_standard = PL_numeric_standard; \
+ if (was_standard) SET_NUMERIC_LOCAL();
+
#define RESTORE_NUMERIC_LOCAL() \
if (was_local) SET_NUMERIC_LOCAL();
}
use Config;
my $have_setlocale = $Config{d_setlocale} eq 'define';
+my $have_strtod = $Config{d_strtod} eq 'define';
$have_setlocale = 0 if $@;
# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
# and mingw32 uses said silly CRT
print \$i, "\n";
EOF
"1,5\n2,5", {}, "Can do math when radix is a comma"); # [perl 115800]
+
+ unless ($have_strtod) {
+ skip("no strtod()", 1);
+ }
+ else {
+ fresh_perl_is(<<"EOF",
+ use POSIX;
+ POSIX::setlocale(POSIX::LC_NUMERIC(),"$comma");
+ my \$one_point_5 = POSIX::strtod("1,5");
+ \$one_point_5 =~ s/0+\$//; # Remove any trailing zeros
+ print \$one_point_5, "\n";
+EOF
+ "1.5", {}, "POSIX::strtod() uses underlying locale");
+ }
}
} # SKIP
-sub last { 12 }
+sub last { 13 }