1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 07:24:16 +00:00

Fix string -> decrec conversion

This commit is contained in:
David Schmenk 2023-02-12 14:13:59 -08:00
parent 1d3de982d6
commit abd9d35cae
2 changed files with 30 additions and 23 deletions

View File

@ -19,14 +19,13 @@ end
// Parse string into decrecord, return SANE conversion output
//
export def str2ext(str, ext)
byte i, s, d
byte i, d
byte decrec[t_decrecord]
word sgnadj, expadj
decrec:sgn = 0
decrec:exp = 0
decrec.sig = 0
s = 1
i = 1
//
// Skip whitespace
@ -51,27 +50,34 @@ export def str2ext(str, ext)
// Parse number
//
while i <= ^str
d = toupper(^(str+i))
d = ^(str+i)
if d >= '0' and d <= '9'
//
// Parse digit
//
decrec.sig[s] = ^(str+i)
decrec:sig++
s++
decrec.sig[decrec.sig] = d
elsif d == '.'
//
// Parse decimal point
//
i++
while i <= ^str
d = toupper(^(str+i))
if d >= '0' and d <= '9'
decrec.sig[s] = ^(str+i)
decrec.sig++
if !decrec:exp
//
// Skip leading zeros
//
while i <= ^str and ^(str+i) == '0'
decrec:exp--
s++
elsif d == 'E'
i++
loop
fin
while i <= ^str
d = ^(str+i)
if d >= '0' and d <= '9'
decrec.sig++
decrec.sig[decrec.sig] = d
decrec:exp--
elsif d == 'E' or d == 'e'
i--
break
else
@ -79,7 +85,7 @@ export def str2ext(str, ext)
fin
i++
loop
elsif d == 'E'
elsif d == 'E' or d == 'e'
//
// Parse exponent
//
@ -108,21 +114,20 @@ export def str2ext(str, ext)
i++
loop
//
// Strip leading zeros from sig
// Strip trailing zeros from sig
//
while decrec.sig > 1 and decrec.sig.1 == '0'
while decrec.sig > 0 and decrec.sig[decrec.sig] == '0'
decrec.sig--
if decrec:exp < 0
decrec:exp--
fin
memcpy(@decrec.sig.1, @decrec.sig.2, decrec.sig)
decrec:exp++
loop
//
// Check for zero
//
if !decrec.sig
decrec.sig = 1
decrec.sig = 1
decrec.sig.1 = '0'
decrec:sgn = 0
decrec:exp = 0
fin
sane:saveZP()
return sane:restoreZP(sane:op2FP(FFEXT|FOD2B, ext, @decrec))

View File

@ -81,6 +81,8 @@ byte[t_keypad] = '0', 3, 16, "[0]"
word = @digitKey
byte[t_keypad] = '.', 7, 16, "[.]"
word = @pointKey
byte[t_keypad] = 'E', 3, 16, "[0]"
word = @digitKey
byte[t_keypad] = 'X', 11, 16, "[X]"
word = @dropKey
byte[t_keypad] = '+', 15, 16, "[+]"
@ -107,7 +109,7 @@ byte[t_keypad] = '^', 30, 14, "[X(^)Y]"
word = @elemsKey
byte[t_keypad] = 'L', 30, 16, "[(L)G2]"
word = @elemsKey
byte[t_keypad] = 'E', 30, 18, "[(E)^X]"
byte[t_keypad] = 'E', 30, 18, "[(P)^X]"
word = @elemsKey
byte[t_keypad] = 'N', 30, 20, "[L(N)X]"
word = @elemsKey
@ -380,7 +382,7 @@ def elemsKey(pkey)#0
is 'L'
fpu:log2X()
break
is 'E'
is 'P'
fpu:powEX()
break
is 'N'
@ -422,7 +424,7 @@ end
def inputKey#0
byte inkey
word pkeys
conio:echo(ECHO_OFF)
while not quit
pkeys = @keypad