diff --git a/ase/awk/misc.c b/ase/awk/misc.c index d4171cf3..bed33422 100644 --- a/ase/awk/misc.c +++ b/ase/awk/misc.c @@ -1,5 +1,5 @@ /* - * $Id: misc.c,v 1.24 2006-10-06 03:33:43 bacon Exp $ + * $Id: misc.c,v 1.25 2006-10-06 14:34:37 bacon Exp $ */ #include @@ -234,6 +234,7 @@ xp_real_t xp_awk_strtoreal (xp_awk_t* awk, const xp_char_t* str) { fraction = 0.0; /*p = str;*/ + p = pexp; goto done; } else @@ -283,7 +284,8 @@ xp_real_t xp_awk_strtoreal (xp_awk_t* awk, const xp_char_t* str) if (!XP_AWK_ISDIGIT (awk, *p)) { /* p = pexp; */ - goto done; + /* goto done; */ + goto no_exp; } while (XP_AWK_ISDIGIT (awk, *p)) { @@ -292,6 +294,7 @@ xp_real_t xp_awk_strtoreal (xp_awk_t* awk, const xp_char_t* str) } } +no_exp: if (exp_negative) exp = frac_exp - exp; else exp = frac_exp + exp; @@ -385,7 +388,7 @@ xp_real_t xp_awk_strxtoreal ( c = *p; if (!XP_AWK_ISDIGIT (awk, c)) { - if ((c != XP_T('.')) || (dec_pt >= 0)) break; + if (c != XP_T('.') || dec_pt >= 0) break; dec_pt = mant_size; } p++; @@ -422,11 +425,13 @@ xp_real_t xp_awk_strxtoreal ( { fraction = 0.0; /*p = str;*/ + p = pexp; goto done; } else { int frac1, frac2; + frac1 = 0; for ( ; mant_size > 9; mant_size--) { @@ -439,47 +444,56 @@ xp_real_t xp_awk_strxtoreal ( } frac1 = 10 * frac1 + (c - XP_T('0')); } + frac2 = 0; for (; mant_size > 0; mant_size--) { - c = *p; - p++; + c = *p++; if (c == XP_T('.')) { c = *p; p++; } - frac2 = 10*frac2 + (c - XP_T('0')); + frac2 = 10 * frac2 + (c - XP_T('0')); } fraction = (1.0e9 * frac1) + frac2; } /* Skim off the exponent */ p = pexp; - if ((*p == XP_T('E')) || (*p == XP_T('e'))) + if (p < end && (*p == XP_T('E') || *p == XP_T('e'))) { p++; - if (*p == XP_T('-')) + + if (p < end) { - exp_negative = 1; - p++; - } - else - { - if (*p == XP_T('+')) p++; - exp_negative = 0; + if (*p == XP_T('-')) + { + exp_negative = 1; + p++; + } + else + { + if (*p == XP_T('+')) p++; + exp_negative = 0; + } } - if (!XP_AWK_ISDIGIT (awk, *p)) + else exp_negative = 0; + + if (!(p < end && XP_AWK_ISDIGIT (awk, *p))) { - /* p = pexp; */ - goto done; + /*p = pexp;*/ + /*goto done;*/ + goto no_exp; } - while (XP_AWK_ISDIGIT (awk, *p)) + + while (p < end && XP_AWK_ISDIGIT (awk, *p)) { exp = exp * 10 + (*p - XP_T('0')); p++; } } +no_exp: if (exp_negative) exp = frac_exp - exp; else exp = frac_exp + exp; @@ -509,6 +523,7 @@ xp_real_t xp_awk_strxtoreal ( else fraction *= dbl_exp; done: + if (endptr != XP_NULL) *endptr = p; return (negative)? -fraction: fraction; } diff --git a/ase/awk/parse.c b/ase/awk/parse.c index e2057eac..1b36688b 100644 --- a/ase/awk/parse.c +++ b/ase/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c,v 1.186 2006-10-06 03:33:43 bacon Exp $ + * $Id: parse.c,v 1.187 2006-10-06 14:34:37 bacon Exp $ */ #include @@ -3283,7 +3283,7 @@ static int __get_token (xp_awk_t* awk) { SET_TOKEN_TYPE (awk, TOKEN_EOF); } - else if (XP_AWK_ISDIGIT (awk, c)) + else if (XP_AWK_ISDIGIT (awk, c) || c == XP_T('.')) { if (__get_number (awk) == -1) return -1; } diff --git a/ase/awk/run.c b/ase/awk/run.c index f0fdc6de..17832244 100644 --- a/ase/awk/run.c +++ b/ase/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c,v 1.225 2006-10-06 03:41:54 bacon Exp $ + * $Id: run.c,v 1.226 2006-10-06 14:34:37 bacon Exp $ */ #include @@ -2838,6 +2838,7 @@ static int __cmp_int_str ( xp_char_t* str; xp_size_t len; xp_long_t r; + xp_real_t rr; int n; r = xp_awk_strxtolong (run->awk, @@ -2850,11 +2851,10 @@ static int __cmp_int_str ( if (((xp_awk_val_int_t*)left)->val < r) return -1; return 0; } +/* TODO: should i do this??? conversion to real and comparision... */ else if (*str == XP_T('.') || *str == XP_T('E') || *str == XP_T('e')) { - /* TODO: */ - /* - r = xp_awk_strxtoreal (run->awk, + rr = xp_awk_strxtoreal (run->awk, ((xp_awk_val_str_t*)right)->buf, ((xp_awk_val_str_t*)right)->len, &str); if (str == ((xp_awk_val_str_t*)right)->buf + @@ -2864,7 +2864,6 @@ static int __cmp_int_str ( if (((xp_awk_val_int_t*)left)->val < rr) return -1; return 0; } - */ } str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); @@ -2926,8 +2925,20 @@ static int __cmp_real_str ( { xp_char_t* str; xp_size_t len; + xp_real_t rr; int n; + rr = xp_awk_strxtoreal (run->awk, + ((xp_awk_val_str_t*)right)->buf, + ((xp_awk_val_str_t*)right)->len, &str); + if (str == ((xp_awk_val_str_t*)right)->buf + + ((xp_awk_val_str_t*)right)->len) + { + if (((xp_awk_val_real_t*)left)->val > rr) return 1; + if (((xp_awk_val_real_t*)left)->val < rr) return -1; + return 0; + } + str = xp_awk_valtostr (run, left, xp_true, XP_NULL, &len); if (str == XP_NULL) { diff --git a/ase/test/awk/comp.awk b/ase/test/awk/comp.awk index 5972e274..c535b2f4 100644 --- a/ase/test/awk/comp.awk +++ b/ase/test/awk/comp.awk @@ -73,6 +73,15 @@ BEGIN { print "010 > \"8\"", (010 > "8"); print "010 < \"8\"", (010 < "8"); + print "--------------------------"; + print "10 == \"10.0\"", (10 == "10.0"); + print "10 != \"10.0\"", (10 != "10.0"); + print "10 >= \"10.0\"", (10 >= "10.0"); + print "10 <= \"10.0\"", (10 <= "10.0"); + print "10 > \"10.0\"", (10 > "10.0"); + print "10 < \"10.0\"", (10 < "10.0"); + + #OFMT="abc"; print "--------------------------"; print "10.0 == \"10\"", (10.0 == "10"); print "10.0 != \"10\"", (10.0 != "10"); @@ -85,4 +94,11 @@ BEGIN { #print a == 1; print (0.234 + 1.01123); + print 12345678901234567890E20; + print .123; + print +.123; + print -.123; + print .123E-; + print +.123E-; + print -.123E-; }