home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / forth / 3653 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.7 KB  |  52 lines

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!waikato.ac.nz!canterbury.ac.nz!lincoln.ac.nz!wronz.org.nz!mentink
  2. Newsgroups: comp.lang.forth
  3. Subject: Help with ... "NUMBER?"
  4. Message-ID: <1992Dec22.080639.89@wronz.org.nz>
  5. From: mentink@wronz.org.nz
  6. Date: 22 Dec 92 08:06:39 +1300
  7. Lines: 43
  8.  
  9.  
  10.  
  11.           Can anyone help, the standard EFORTH word-set includes the word
  12. NUMBER? which converts a number string entered interactivly by the user.
  13. Although it accepts hex numbers e.g $4000, it does not conform to the
  14. usual FORTH and allow you to enter a double number e.g 123.45
  15.  
  16. Can anyone help by providing a modification of the EFORTH source for the
  17. word. Follows below ....... 
  18.  
  19.   Alternatively....
  20.   Provide a seperate word to allow you to enter a double number on the
  21.   stack.
  22.  
  23.  
  24.   Thanks in advance.
  25.  
  26. / --------------------- Source starts here -----------------------------
  27.  
  28.  
  29. : NUMBER? ( a -- n T, a F )
  30.   BASE @ >R  0 OVER COUNT ( a 0 b n)
  31.   OVER C@ [ CHAR $ ] LITERAL =
  32.   IF HEX SWAP BYTE+ SWAP 1 - THEN ( a 0 b' n')
  33.   OVER C@ [ CHAR - ] LITERAL = >R ( a 0 b n)
  34.   SWAP R@ - SWAP R@ + ( a 0 b" n") ?DUP
  35.   IF 1 - ( a 0 b n)
  36.     FOR DUP >R C@ BASE @ DIGIT?
  37.       WHILE SWAP BASE @ * +  R> BYTE+
  38.     NEXT R@ ( ?sign) NIP ( b) IF NEGATE THEN SWAP
  39.       ELSE R> R> ( b index) 2DROP ( digit number) 2DROP 0
  40.       THEN DUP
  41.   THEN R> ( n ?sign) 2DROP R> BASE ! ;
  42.  
  43.   --------------------------------------------------------------------------
  44.     Bernie Mentink   ( Christchurch N.Z. )
  45.     email: mentink@wronz.org.nz
  46.  
  47.           .... Some things have to be seen to be believed,
  48.                     Most things have to be believed to be seen ....
  49.     -----------------------------------------------------------------
  50.  
  51. 
  52.