View Full Version : Max-Forth FP terminal input
Can you show me an example of a terminal keyboard input routine for floating point. I suspect that FNUMBER would be used in place of CONVERT. Thanks.
RMDumse
07-16-01, 12:00 PM
Your suspicions are correct. CONVERT and FNUMBER are both primitives of NUMBER. FNUMBER is the most general input. FNUMBER in V3.5 will convert all numbers, floats or otherwise.
NUMBER calls FNUMBER, then does a check for an error. Usually in run time situations you want to avoid taking this error routing (which leads back to the outer interpreter and not back to your program) and do your error checking yourself.
NUMBER is defined in V3.5 as:
: NUMBER
FNUMB C@ ( look at next char
BL - (see if it is the same as a blank
0 ?ERROR ( call to see if it is an error, return if not
;
CONVERT is a deeper primative that will convert a string up to the first non-numeric character, and return. The non-numeric character could be a space, or a decimal point, or a floating point character (e) or something unexpected which would be considered a true error (by
something else beyond CONVERT).
So you use FNUMBER the same way you do NUMBER without the worry of loosing control of the program on error. Feed it a double word zero, and the address of the counted string (-1 as I vaguely recall) to convert. Check DPL to determine what kind of result has been returned. If DPL is FFFF, the result is a single precision number left on the stack (having no decimal point embedded). If DPL is FFFE, the result is a float, and it is already on the float stack. Any other value in DPL says a decimal point was encountered in the string, and the result is a double precision number left on the stack.
vBulletin v3.0.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.