This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
parts/ppptools.pl: Add comments, white-space, m//x
[perl5.git] / numeric.c
index d4e3493..6f3fd34 100644 (file)
--- a/numeric.c
+++ b/numeric.c
@@ -66,6 +66,8 @@ S_strtod(pTHX_ const char * const s, char ** e)
 
     result = strtod(s, e);
 
+#  else
+#    error No strtod() equivalent found
 #  endif
 
     RESTORE_LC_NUMERIC();
@@ -88,14 +90,14 @@ It properly handles the locale radix character, meaning it expects a dot except
 when called from within the scope of S<C<use locale>>, in which case the radix
 character should be that specified by the current locale.
 
-The synonym Strod() may be used instead.
+The synonym Strtod() may be used instead.
 
 =cut
 
 */
 
 NV
-my_strtod(const char * const s, char **e)
+Perl_my_strtod(const char * const s, char **e)
 {
     dTHX;
 
@@ -225,6 +227,12 @@ C<PERL_SCAN_DISALLOW_PREFIX> is set in C<*flags> on entry.  If
 C<PERL_SCAN_ALLOW_UNDERSCORES> is set in C<*flags> then the binary
 number may use C<"_"> characters to separate digits.
 
+=for apidoc Amnh||PERL_SCAN_ALLOW_UNDERSCORES
+=for apidoc Amnh||PERL_SCAN_DISALLOW_PREFIX
+=for apidoc Amnh||PERL_SCAN_GREATER_THAN_UV_MAX
+=for apidoc Amnh||PERL_SCAN_SILENT_ILLDIGIT
+=for apidoc Amnh||PERL_SCAN_TRAILING
+
 =cut
 
 Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE
@@ -676,6 +684,13 @@ If an infinity or a not-a-number is recognized, C<*sp> will point to
 one byte past the end of the recognized string.  If the recognition fails,
 zero is returned, and C<*sp> will not move.
 
+=for apidoc Amn|bool|IS_NUMBER_GREATER_THAN_UV_MAX
+=for apidoc Amn|bool|IS_NUMBER_INFINITY
+=for apidoc Amn|bool|IS_NUMBER_IN_UV
+=for apidoc Amn|bool|IS_NUMBER_NAN
+=for apidoc Amn|bool|IS_NUMBER_NEG
+=for apidoc Amn|bool|IS_NUMBER_NOT_INT
+
 =cut
 */
 
@@ -1549,6 +1564,15 @@ Perl_my_atof3(pTHX_ const char* orig, NV* value, const STRLEN len)
         if ((endp = S_my_atof_infnan(aTHX_ s, negative, send, value)))
             return endp;
 
+        /* strtold() accepts 0x-prefixed hex and in POSIX implementations,
+           0b-prefixed binary numbers, which is backward incompatible
+        */
+        if ((len == 0 || len >= 2) && *s == '0' &&
+            (isALPHA_FOLD_EQ(s[1], 'x') || isALPHA_FOLD_EQ(s[1], 'b'))) {
+            *value = 0;
+            return (char *)s+1;
+        }
+
         /* If the length is passed in, the input string isn't NUL-terminated,
          * and in it turns out the function below assumes it is; therefore we
          * create a copy and NUL-terminate that */