[svn:parrot] r39371 - in branches/tt24_unicode_numifications: src/string t/op

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Jun 3 22:37:26 UTC 2009


Author: bacek
Date: Wed Jun  3 22:37:23 2009
New Revision: 39371
URL: https://trac.parrot.org/parrot/changeset/39371

Log:
[core] Add DEPRECATED handling for non-canonical NaN and Inf.

Modified:
   branches/tt24_unicode_numifications/src/string/api.c
   branches/tt24_unicode_numifications/t/op/string.t

Modified: branches/tt24_unicode_numifications/src/string/api.c
==============================================================================
--- branches/tt24_unicode_numifications/src/string/api.c	Wed Jun  3 21:04:03 2009	(r39370)
+++ branches/tt24_unicode_numifications/src/string/api.c	Wed Jun  3 22:37:23 2009	(r39371)
@@ -2182,10 +2182,14 @@
     INTVAL        d         = 0;    /* Integer descriminator */
     int           d_is_safe = 1;    /* We can use integer mantissa */
     int           d_length  = 0;
+    int           check_nan = 0;    /* Support for deprecated nan, inf */
     String_iter iter;
     UINTVAL     offs;
     number_parse_state state = parse_start;
 
+    if (!s)
+        return 0.0;
+
     if (Parrot_str_equal(interp, s, CONST_STRING(interp, "Inf")))
         return PARROT_FLOATVAL_INF_POSITIVE;
     else if (Parrot_str_equal(interp, s, CONST_STRING(interp, "-Inf")))
@@ -2215,8 +2219,10 @@
                     state = parse_after_dot;
                 else if (isspace(c))
                     ; /* Do nothing */
-                else
-                    state = parse_end;
+                else {
+                    check_nan = 1;
+                    state     = parse_end;
+                }
                 break;
 
             case parse_before_dot:
@@ -2244,8 +2250,10 @@
                         f = m;
                     mantissa = f;
                 }
-                else
-                    state = parse_end;
+                else {
+                    check_nan = 1;
+                    state     = parse_end;
+                }
                 break;
 
             case parse_after_dot:
@@ -2292,6 +2300,20 @@
         }
     }
 
+    /* DEPRECATED support for non-canonical NaN and Inf */
+    /* charpos <=2 because for "-i" iter will be advanced to next char already */
+    if (check_nan && (iter.charpos <= 2)) {
+        STRING *t = Parrot_str_upcase(interp, s);
+        if (Parrot_str_equal(interp, t, CONST_STRING(interp, "NAN")))
+            return PARROT_FLOATVAL_NAN_QUIET;
+        else if (Parrot_str_equal(interp, t, CONST_STRING(interp, "INF")))
+            return PARROT_FLOATVAL_INF_POSITIVE;
+        else if (Parrot_str_equal(interp, t, CONST_STRING(interp, "-INF")))
+            return PARROT_FLOATVAL_INF_NEGATIVE;
+        else
+            return 0.0;
+    }
+
     if (d && d_is_safe) {
         f = mantissa + (1.0 * d / powl(10, d_length));
     }

Modified: branches/tt24_unicode_numifications/t/op/string.t
==============================================================================
--- branches/tt24_unicode_numifications/t/op/string.t	Wed Jun  3 21:04:03 2009	(r39370)
+++ branches/tt24_unicode_numifications/t/op/string.t	Wed Jun  3 22:37:23 2009	(r39371)
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 164;
+use Parrot::Test tests => 165;
 use Parrot::Config;
 
 =head1 NAME
@@ -2935,6 +2935,21 @@
 2147483647
 -2147483648
 OUT
+pir_output_is( <<'CODE', <<'OUT', 'Non canonical nan and inf' );
+.sub main :main
+    $N0 = 'nan'
+    say $N0
+    $N0 = 'iNf'
+    say $N0
+    $N0 = '-INF'
+    say $N0
+.end
+CODE
+NaN
+Inf
+-Inf
+OUT
+
 
 
 # Local Variables:


More information about the parrot-commits mailing list