Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
713B

  1. : _pd ( a -- n f, parse decimal )
  2. ( We read the first char outside of the loop because it *has*
  3. to be nonzero, which means _pdacc *has* to return 0. )
  4. C@+ OVER C@ 0 ( a len firstchar startat )
  5. ( if we have '-', we only advance. more processing later. )
  6. SWAP '-' = IF 1+ THEN ( a len startat )
  7. ( We loop until _pdacc is nonzero, which means either WS or
  8. non-digit. 1 means WS, which means parsing was a success.
  9. -1 means non-digit, which means we have a non-decimal. )
  10. 0 ROT ROT ( len ) ( startat ) DO ( a r )
  11. OVER I + C@ ( a r c ) _pdacc ( a r f )
  12. IF DROP 1- 0 UNLOOP EXIT THEN LOOP ( a r )
  13. ( if we had '-', we need to invert result. )
  14. SWAP C@ '-' = IF 0 -^ THEN 1 ( r 1 ) ;