home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!waikato.ac.nz!canterbury.ac.nz!lincoln.ac.nz!wronz.org.nz!mentink
- Newsgroups: comp.lang.forth
- Subject: Help with ... "NUMBER?"
- Message-ID: <1992Dec22.080639.89@wronz.org.nz>
- From: mentink@wronz.org.nz
- Date: 22 Dec 92 08:06:39 +1300
- Lines: 43
-
-
-
- Can anyone help, the standard EFORTH word-set includes the word
- NUMBER? which converts a number string entered interactivly by the user.
- Although it accepts hex numbers e.g $4000, it does not conform to the
- usual FORTH and allow you to enter a double number e.g 123.45
-
- Can anyone help by providing a modification of the EFORTH source for the
- word. Follows below .......
-
- Alternatively....
- Provide a seperate word to allow you to enter a double number on the
- stack.
-
-
- Thanks in advance.
-
- / --------------------- Source starts here -----------------------------
-
-
- : NUMBER? ( a -- n T, a F )
- BASE @ >R 0 OVER COUNT ( a 0 b n)
- OVER C@ [ CHAR $ ] LITERAL =
- IF HEX SWAP BYTE+ SWAP 1 - THEN ( a 0 b' n')
- OVER C@ [ CHAR - ] LITERAL = >R ( a 0 b n)
- SWAP R@ - SWAP R@ + ( a 0 b" n") ?DUP
- IF 1 - ( a 0 b n)
- FOR DUP >R C@ BASE @ DIGIT?
- WHILE SWAP BASE @ * + R> BYTE+
- NEXT R@ ( ?sign) NIP ( b) IF NEGATE THEN SWAP
- ELSE R> R> ( b index) 2DROP ( digit number) 2DROP 0
- THEN DUP
- THEN R> ( n ?sign) 2DROP R> BASE ! ;
-
- --------------------------------------------------------------------------
- Bernie Mentink ( Christchurch N.Z. )
- email: mentink@wronz.org.nz
-
- .... Some things have to be seen to be believed,
- Most things have to be believed to be seen ....
- -----------------------------------------------------------------
-
-