2020-10-28 18:06:58 -04:00
|
|
|
: _pd ( a -- n f, parse decimal )
|
|
|
|
( We read the first char outside of the loop because it *has*
|
|
|
|
to be nonzero, which means _pdacc *has* to return 0. )
|
|
|
|
C@+ OVER C@ 0 ( a len firstchar startat )
|
|
|
|
( if we have '-', we only advance. more processing later. )
|
|
|
|
SWAP '-' = IF 1+ THEN ( a len startat )
|
|
|
|
( We loop until _pdacc is nonzero, which means either WS or
|
|
|
|
non-digit. 1 means WS, which means parsing was a success.
|
|
|
|
-1 means non-digit, which means we have a non-decimal. )
|
|
|
|
0 ROT ROT ( len ) ( startat ) DO ( a r )
|
|
|
|
OVER I + C@ ( a r c ) _pdacc ( a r f )
|
|
|
|
IF DROP 1- 0 UNLOOP EXIT THEN LOOP ( a r )
|
|
|
|
( if we had '-', we need to invert result. )
|
|
|
|
SWAP C@ '-' = IF 0 -^ THEN 1 ( r 1 ) ;
|