This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
infnan: Simplify inf parsing.
authorJarkko Hietaniemi <jhi@iki.fi>
Sun, 25 Jan 2015 17:27:44 +0000 (12:27 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 28 Jan 2015 11:52:32 +0000 (06:52 -0500)
Accept anything beginning with /^inf/i,
but warn if there's trailing stuff.

numeric.c
t/op/infnan.t

index 66b0883..7819c60 100644 (file)
--- a/numeric.c
+++ b/numeric.c
@@ -641,21 +641,11 @@ Perl_grok_infnan(const char** sp, const char* send)
         s++; if (s == send) return 0;
         if (isALPHA_FOLD_EQ(*s, 'F')) {
             s++;
-            if (s < send && (isALPHA_FOLD_EQ(*s, 'I'))) {
-                s++; if (s == send || isALPHA_FOLD_NE(*s, 'N')) return 0;
-                s++; if (s == send || isALPHA_FOLD_NE(*s, 'I')) return 0;
-                s++; if (s == send || isALPHA_FOLD_NE(*s, 'T')) return 0;
-                s++; if (s == send ||
-                         /* allow either Infinity or Infinite */
-                         !(isALPHA_FOLD_EQ(*s, 'Y') ||
-                           isALPHA_FOLD_EQ(*s, 'E'))) return 0;
-                s++; if (s < send) return 0;
-            } else {
-                while (*s == '0') { /* 1.#INF00 */
-                    s++;
-                }
-                if (*s)
-                    return 0;
+            while (*s == '0') { /* 1.#INF00 */
+                s++;
+            }
+            if (*s) {
+                flags |= IS_NUMBER_TRAILING;
             }
             flags |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;
         }
index 83ec5f6..6e59121 100644 (file)
@@ -27,7 +27,6 @@ my $NaN;
 }
 
 my @PInf = ("Inf", "inf", "INF", "+Inf",
-            "Infinity", "INFINITE",
             "1.#INF", "1#INF", "1.#INF00");
 my @NInf = map { "-$_" } grep { ! /^\+/ } @PInf;
 
@@ -245,14 +244,14 @@ TODO: {
 }
 
 SKIP: {
-    my @FInf = qw(Info Infiniti Infinityz);
+    my @FInf = qw(Infinity Infinite Info Inf123 Infiniti Infinityz);
     if ($Config{usequadmath}) {
         skip "quadmath strtoflt128() accepts false infinities", scalar @FInf;
     }
-    # Silence "isn't numeric in addition", that's kind of the point.
-    local $^W = 0;
     for my $i (@FInf) {
-        cmp_ok("$i" + 0, '==', 0, "false infinity $i");
+        # Silence "isn't numeric in addition", that's kind of the point.
+        local $^W = 0;
+        cmp_ok("$i" + 0, '==', $PInf, "false infinity $i");
     }
 }