diff src/std.c @ 8:25b2b501a5fa

Cleaned up the stack operations The stack operations now handle error checking correctly (and are no longer a tangled mass of duplicated code) atoi now will work correctly if there is a "+" symbol in front of the number atof will no longer treat something like "aoe235.357" as ".357"
author Jonathan Pevarnek <pevarnj@gmail.com>
date Wed, 09 Mar 2011 12:08:48 -0500
parents 348c59c36703
children 525eab23e68a
line wrap: on
line diff
--- a/src/std.c	Sun Mar 06 01:55:09 2011 -0500
+++ b/src/std.c	Wed Mar 09 12:08:48 2011 -0500
@@ -53,12 +53,12 @@
 
 int atoi(char *a)
 {
-	int neg = 0;
+	short neg = 0;
 	int n = 0;
 	if(*a == '-') {
 		neg = 1;
 		a++;
-	}
+	} else if(*a == '+') a++;
 	while(*a >= '0' && *a <= '9')
 		n = n*10 + (*a++ - '0');
 	if(neg) n *= -1;
@@ -71,7 +71,7 @@
 	double x = 0;
 	double dec = .1;
 	while(*a != '.') {
-		if(*a == '\0') return n;
+		if(!(*a >= '0' && *a <= '9')) return n;
 		a++;
 	} a++; //a will be immediately after the decimal point
 	while(*a >= '0' && *a <= '9') { //goes through the decimal part