fixed a bug in string_to_fpdec().

supports the plus sign before a numeric literal
This commit is contained in:
hyunghwan.chung 2019-02-19 05:02:37 +00:00
parent d384801eec
commit 4301066c76
3 changed files with 11 additions and 7 deletions

View File

@ -234,7 +234,9 @@ extend MyObject
[ ((-10.19 scale: 0) scale) = (10 scale) ],
[ (-9p10 scale) = (-10.000000000 scale) ],
[ (-9p10.123 scale) = (-10.123000000 scale) ],
[ (+3p100.1 + 16rffff + +5p1.22 + -5p1.223) = 65635.09700 ],
## =========================
[
| b |
b := [:n | (n > 0) ifTrue: [ n * (b value: n - 1)] ifFalse: [1]].

View File

@ -29,8 +29,9 @@ class MyObject(Object)
##rec := [ :y :z | (108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y)) truncate: 18. ].
##rec := [ :y :z | (108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y)) truncate: 16. ].
##rec := [ :y :z | 108.0000000000000000000000 - (815.000000000000000000 - (1500.0000000000000000 div: z) div: y) ].
rec := [ :y :z | (108.0 scale: 22) - ((815 scale: 18) - ((1500 scale: 16) div: z) div: y) ].
##rec := [ :y :z | (108.0 scale: 22) - ((815 scale: 18) - ((1500 scale: 16) div: z) div: y) ].
##rec := [ :y :z | 108.000000000000000000000000000000 - (815.00000000000000000000000000 - (1500.0000000000000000 div: z) div: y) ].
rec := [ :y :z | 22p108 - (18p815 - (16p1500 div: z) div: y) ].
## results := %( 4.0, 425 div: 100.0 ) asOrderedCollection.
@ -90,6 +91,6 @@ class MyObject(Object)
| tb |
tb := tc at: idx.
System log(System.Log.INFO, idx asString, (if (tb value) { ' PASS' } else { ' FAIL' }), S'\n').
]
].
}
}

View File

@ -709,13 +709,14 @@ static moo_oop_t string_to_fpdec (moo_t* moo, moo_oocs_t* str, int prescaled)
moo_oow_t pos, len;
moo_oow_t scale = 0, xscale = 0;
moo_oop_t v;
int base = 10;
int base = 10, dotted = 0;
pos = str->len;
while (pos > 0)
{
if (str->ptr[--pos] == '.')
{
dotted = 1;
scale = str->len - pos - 1;
MOO_ASSERT (moo, scale > 0);
MOO_ASSERT (moo, scale <= MOO_SMOOI_MAX);
@ -725,7 +726,7 @@ static moo_oop_t string_to_fpdec (moo_t* moo, moo_oocs_t* str, int prescaled)
}
pos = 0;
len = str->len - 1;
len = str->len - dotted;
if (str->ptr[pos] == '+' || str->ptr[pos] == '-')
{
if (str->ptr[pos] - '+') base = -10;
@ -1530,6 +1531,8 @@ static int get_numlit (moo_t* moo, int negated)
moo_oow_t scale = 0;
fixed_point:
SET_TOKEN_TYPE (moo, (xscale > 0? MOO_IOTOK_SCALEDFPDECLIT: MOO_IOTOK_FPDECLIT));
period = moo->c->lxc;
GET_CHAR_TO (moo, c);
if (!is_digitchar(c))
@ -1567,8 +1570,6 @@ static int get_numlit (moo_t* moo, int negated)
while (is_digitchar(c));
MOO_ASSERT (moo, scale > 0 && scale <= MOO_SMOOI_MAX);
SET_TOKEN_TYPE (moo, (xscale > 0? MOO_IOTOK_SCALEDFPDECLIT: MOO_IOTOK_FPDECLIT));
unget_char (moo, &moo->c->lxc);
}
}
@ -1823,7 +1824,7 @@ static int get_binsel (moo_t* moo)
GET_CHAR (moo);
/* special case if a minus is followed by a digit immediately */
if (oc == '-' && is_digitchar(moo->c->lxc.c)) return get_numlit (moo, 1);
if ((oc == '-' || oc == '+') && is_digitchar(moo->c->lxc.c)) return get_numlit (moo, 1);
#if 1
/* up to 2 characters only */