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

bacek at svn.parrot.org bacek at svn.parrot.org
Sun May 31 23:32:11 UTC 2009


Author: bacek
Date: Sun May 31 23:32:10 2009
New Revision: 39300
URL: https://trac.parrot.org/parrot/changeset/39300

Log:
[core][t] Handle corner cases of Parrot_str_to_num correctly

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	Sun May 31 22:45:56 2009	(r39299)
+++ branches/tt24_unicode_numifications/src/string/api.c	Sun May 31 23:32:10 2009	(r39300)
@@ -2224,7 +2224,7 @@
                     f = f*10.0 + (c-'0');
                     m = m*10 + (c-'0');
                     /* Integer overflow for mantissa */
-                    if (m > max_safe)
+                    if (m >= max_safe)
                         m_is_safe = 0;
                 }
                 else if (c == '.') {
@@ -2297,10 +2297,13 @@
     }
 
     f = f * sign;
-    if (e_sign == 1)
-        f *= powl(10, e);
-    else
-        f /= powl(10, e);
+
+    if (e) {
+        if (e_sign == 1)
+            f *= powl(10, e);
+        else
+            f /= powl(10, e);
+    }
 
     return f;
 }

Modified: branches/tt24_unicode_numifications/t/op/string.t
==============================================================================
--- branches/tt24_unicode_numifications/t/op/string.t	Sun May 31 22:45:56 2009	(r39299)
+++ branches/tt24_unicode_numifications/t/op/string.t	Sun May 31 23:32:10 2009	(r39300)
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 163;
+use Parrot::Test tests => 164;
 use Parrot::Config;
 
 =head1 NAME
@@ -2926,6 +2926,16 @@
 Foo/Bar
 OUT
 
+pir_output_is( <<'CODE', <<'OUT', 'Corner cases of numification' );
+.sub main :main
+    say 2147483647.0
+    say -2147483648.0
+.end
+CODE
+2147483647
+-2147483648
+OUT
+
 
 # Local Variables:
 #   mode: cperl


More information about the parrot-commits mailing list