develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34219 - trunk/languages/perl6/src/pmc

From:
pmichaud
Date:
December 21, 2008 12:16
Subject:
[svn:parrot] r34219 - trunk/languages/perl6/src/pmc
Message ID:
20081221201641.A8EA6CBA12@x12.develooper.com
Author: pmichaud
Date: Sun Dec 21 12:16:41 2008
New Revision: 34219

Modified:
   trunk/languages/perl6/src/pmc/perl6str.pmc

Log:
[rakudo]:  Recognize numification of "Inf" and "NaN" strings.
* Also fix strlen() bug introduced in r34167 patch.


Modified: trunk/languages/perl6/src/pmc/perl6str.pmc
==============================================================================
--- trunk/languages/perl6/src/pmc/perl6str.pmc	(original)
+++ trunk/languages/perl6/src/pmc/perl6str.pmc	Sun Dec 21 12:16:41 2008
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"
 #include <ctype.h>
 #include <math.h>
+#include <string.h>
 
 
 static
@@ -126,7 +127,7 @@
 
         if (s && s->strstart) {
             const char *s1         = s->strstart;
-            const char * const end = s1 + strlen(s1);
+            const char * const end = s1 + s->bufused;
 
             /* skip leading whitespace */
             while (s1 < end && isspace((unsigned char)*s1))
@@ -156,6 +157,20 @@
                 sign = -1.0; s1++;
             }
 
+            if (tolower(*s1) == 'i') {
+                if (strncasecmp(s1, "inf", 3) == 0) s1 += 3;
+                while (s1 < end && isspace((unsigned char)*s1))
+                    s1++;
+                return (s1 == end) ? sign * atof("inf") : 0.0;
+            }
+
+            if (tolower(*s1) == 'n') {
+                if (strncasecmp(s1, "nan", 3) == 0) s1 += 3;
+                while (s1 < end && isspace((unsigned char)*s1)) 
+                    s1++;
+                return (s1 == end) ? sign * atof("nan") : 0.0;
+            }
+
             /* handle 0x, 0o, 0d, 0b radix */
             if (s1 < end && *s1 == '0') {
                 s1++;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About