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:
parent
1d3de982d6
commit
abd9d35cae
@ -19,14 +19,13 @@ end
|
|||||||
// Parse string into decrecord, return SANE conversion output
|
// Parse string into decrecord, return SANE conversion output
|
||||||
//
|
//
|
||||||
export def str2ext(str, ext)
|
export def str2ext(str, ext)
|
||||||
byte i, s, d
|
byte i, d
|
||||||
byte decrec[t_decrecord]
|
byte decrec[t_decrecord]
|
||||||
word sgnadj, expadj
|
word sgnadj, expadj
|
||||||
|
|
||||||
decrec:sgn = 0
|
decrec:sgn = 0
|
||||||
decrec:exp = 0
|
decrec:exp = 0
|
||||||
decrec.sig = 0
|
decrec.sig = 0
|
||||||
s = 1
|
|
||||||
i = 1
|
i = 1
|
||||||
//
|
//
|
||||||
// Skip whitespace
|
// Skip whitespace
|
||||||
@ -51,27 +50,34 @@ export def str2ext(str, ext)
|
|||||||
// Parse number
|
// Parse number
|
||||||
//
|
//
|
||||||
while i <= ^str
|
while i <= ^str
|
||||||
d = toupper(^(str+i))
|
d = ^(str+i)
|
||||||
if d >= '0' and d <= '9'
|
if d >= '0' and d <= '9'
|
||||||
//
|
//
|
||||||
// Parse digit
|
// Parse digit
|
||||||
//
|
//
|
||||||
decrec.sig[s] = ^(str+i)
|
|
||||||
decrec:sig++
|
decrec:sig++
|
||||||
s++
|
decrec.sig[decrec.sig] = d
|
||||||
elsif d == '.'
|
elsif d == '.'
|
||||||
//
|
//
|
||||||
// Parse decimal point
|
// Parse decimal point
|
||||||
//
|
//
|
||||||
i++
|
i++
|
||||||
while i <= ^str
|
if !decrec:exp
|
||||||
d = toupper(^(str+i))
|
//
|
||||||
if d >= '0' and d <= '9'
|
// Skip leading zeros
|
||||||
decrec.sig[s] = ^(str+i)
|
//
|
||||||
decrec.sig++
|
while i <= ^str and ^(str+i) == '0'
|
||||||
decrec:exp--
|
decrec:exp--
|
||||||
s++
|
i++
|
||||||
elsif d == 'E'
|
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--
|
i--
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -79,7 +85,7 @@ export def str2ext(str, ext)
|
|||||||
fin
|
fin
|
||||||
i++
|
i++
|
||||||
loop
|
loop
|
||||||
elsif d == 'E'
|
elsif d == 'E' or d == 'e'
|
||||||
//
|
//
|
||||||
// Parse exponent
|
// Parse exponent
|
||||||
//
|
//
|
||||||
@ -108,21 +114,20 @@ export def str2ext(str, ext)
|
|||||||
i++
|
i++
|
||||||
loop
|
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--
|
decrec.sig--
|
||||||
if decrec:exp < 0
|
decrec:exp++
|
||||||
decrec:exp--
|
|
||||||
fin
|
|
||||||
memcpy(@decrec.sig.1, @decrec.sig.2, decrec.sig)
|
|
||||||
loop
|
loop
|
||||||
//
|
//
|
||||||
// Check for zero
|
// Check for zero
|
||||||
//
|
//
|
||||||
if !decrec.sig
|
if !decrec.sig
|
||||||
decrec.sig = 1
|
decrec.sig = 1
|
||||||
decrec.sig.1 = '0'
|
decrec.sig.1 = '0'
|
||||||
|
decrec:sgn = 0
|
||||||
|
decrec:exp = 0
|
||||||
fin
|
fin
|
||||||
sane:saveZP()
|
sane:saveZP()
|
||||||
return sane:restoreZP(sane:op2FP(FFEXT|FOD2B, ext, @decrec))
|
return sane:restoreZP(sane:op2FP(FFEXT|FOD2B, ext, @decrec))
|
||||||
|
@ -81,6 +81,8 @@ byte[t_keypad] = '0', 3, 16, "[0]"
|
|||||||
word = @digitKey
|
word = @digitKey
|
||||||
byte[t_keypad] = '.', 7, 16, "[.]"
|
byte[t_keypad] = '.', 7, 16, "[.]"
|
||||||
word = @pointKey
|
word = @pointKey
|
||||||
|
byte[t_keypad] = 'E', 3, 16, "[0]"
|
||||||
|
word = @digitKey
|
||||||
byte[t_keypad] = 'X', 11, 16, "[X]"
|
byte[t_keypad] = 'X', 11, 16, "[X]"
|
||||||
word = @dropKey
|
word = @dropKey
|
||||||
byte[t_keypad] = '+', 15, 16, "[+]"
|
byte[t_keypad] = '+', 15, 16, "[+]"
|
||||||
@ -107,7 +109,7 @@ byte[t_keypad] = '^', 30, 14, "[X(^)Y]"
|
|||||||
word = @elemsKey
|
word = @elemsKey
|
||||||
byte[t_keypad] = 'L', 30, 16, "[(L)G2]"
|
byte[t_keypad] = 'L', 30, 16, "[(L)G2]"
|
||||||
word = @elemsKey
|
word = @elemsKey
|
||||||
byte[t_keypad] = 'E', 30, 18, "[(E)^X]"
|
byte[t_keypad] = 'E', 30, 18, "[(P)^X]"
|
||||||
word = @elemsKey
|
word = @elemsKey
|
||||||
byte[t_keypad] = 'N', 30, 20, "[L(N)X]"
|
byte[t_keypad] = 'N', 30, 20, "[L(N)X]"
|
||||||
word = @elemsKey
|
word = @elemsKey
|
||||||
@ -380,7 +382,7 @@ def elemsKey(pkey)#0
|
|||||||
is 'L'
|
is 'L'
|
||||||
fpu:log2X()
|
fpu:log2X()
|
||||||
break
|
break
|
||||||
is 'E'
|
is 'P'
|
||||||
fpu:powEX()
|
fpu:powEX()
|
||||||
break
|
break
|
||||||
is 'N'
|
is 'N'
|
||||||
@ -422,7 +424,7 @@ end
|
|||||||
def inputKey#0
|
def inputKey#0
|
||||||
byte inkey
|
byte inkey
|
||||||
word pkeys
|
word pkeys
|
||||||
|
|
||||||
conio:echo(ECHO_OFF)
|
conio:echo(ECHO_OFF)
|
||||||
while not quit
|
while not quit
|
||||||
pkeys = @keypad
|
pkeys = @keypad
|
||||||
|
Loading…
Reference in New Issue
Block a user