Mercurial > hg > index.cgi
changeset 87:3bfd978ddb39
Make corrections in floating point parsing.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 16 Oct 2023 16:48:46 -0600 |
parents | de42b8f77bc2 |
children | a8467c798450 |
files | src/number.s |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/number.s Mon Oct 16 00:52:50 2023 -0600 +++ b/src/number.s Mon Oct 16 16:48:46 2023 -0600 @@ -143,6 +143,8 @@ bra val_parsenum1 val_parsenum0 jsr nextchar ; fetch next input val_parsenum1 bcs val_parsenum3 ; brif digit - short ciruit other checks + cmpa #'. ; does it start with a decimal? + beq val_parsenum5 ; brif so cmpa #'+ ; unary plus? beq val_parsenum0 ; brif so - it's a no-op but supported for symmetry with unary minus cmpa #'- ; negative? @@ -157,7 +159,9 @@ suba #0x30 ; binary-ize the digit bne val_parsenum3a ; brif not zero tstb ; no digits? - beq val_parsenum2 ; brif so - skip leading zeroes + bne val_parsenum3a ; brif not - we've seen something significant + ldb fpaextra+1 ; decimal seen? + bne val_parsenum2 ; brif not - skip leading zeroes val_parsenum3a ldb #0x11 ; put in both digit spots mul andb fpaextra+3 ; only keep the one we need @@ -174,7 +178,7 @@ bra val_parsenum2 ; go handle another digit or whatever val_parsenum5 cmpa #'. ; decimal? bne val_parsenum6 ; brif not - com fpaextra ; flag decimal seen + com fpaextra+1 ; flag decimal seen lbeq SNERROR ; brif already seen a decimal point - syntax error bra val_parsenum2 ; go parse more digits val_parsenum6 cmpa #'E ; decimal exponent? @@ -211,7 +215,7 @@ ; By ensuring there were no leading zeroes converted, the result is already pre-normalized without losing precision due ; to an aribtrary number of leading zeroes. cmpb fpaextra ; is the exponent less than the number of digits? - bgt val_parsenum13 ; brif so - return floating point (signed comparison!) + blt val_parsenum13 ; brif so - return floating point (signed comparison!) cmpb #10 ; is exponent in the range for a binary integer? bgt val_parsenum13 ; brif not - return floating point ; Compare with 2147483648, the maximum *negative* value; note that this is a floating point comparison because we @@ -234,7 +238,7 @@ val_parsenum13 lda #valtype_float ; set return value to floating point sta val0+val.type lda fpa0+fpa.exp ; put the bias into the exponent but subtract one for leading digit - adda #63 + adda #64 sta fpa0+fpa.exp ldy #val0+val.value ; normalize/round and return the result jmp fps_normalize