<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>

NUMBER Search:

In Parsing Words in TurboForth Kernal

Word Name: NUMBER
Type: Standard word
Data Stack Signature: address length -- value flag
Return Stack Signature: --
Availability: V1.0  V1.1  V1.2

Attempts to convert the string at address with length length into a number.




If fully successful the number (value) is placed onto the stack and flag will be 0. If it fails (for example contains an illegal character) then a partial number will be placed onto the stack for value (the value computed up until the failure) and flag will be >0. Thus, if flag>0 the string failed to parse fully as a number.

A minus sign is permitted for negative numbers.

NUMBER parses numbers from the input stream in the current number base, as determined by BASE. Eg. If BASE=16 then digits 0-9 and A-F are considered legal and will be parsed properly.

A facility also exists called 'quick hex' that allows a number to be entered in base 16, by placing a $ symbol at the beginning of the string. This avoids the need to change BASE to enter a hex number. E.g. instead of HEX FEED DECIMAL you can simply type $FEED. The number will be parsed as a hexadecimal number without the need to change BASE.

The same facility also exists for binary numbers: Simply precede the number with a % symbol. E.g. %1001 = 9 decimal.

The numbers returned are (by default) singles (16 bits). NUMBER can also return a double (32-bit (2 stack cells)) value by including a period in the number string. E.g. 100. 1.00 10.0 .100 will all return 100 decimal (assuming BASE=10) as a double, occupying two stack cells. The stack signature when returning a double value is: address length -- value_lsb value_msb flag.

The various facilities can be mixed. For example, -$F. means -15 as a double. - $ and . can be specified in any order. However, $ or % if required, should be specified before any number digits. - and . can be placed anywhere in the string.

See Also: WORD  BASE 

<< Home | About Forth | About TurboForth | Download | Language Reference | Resources | Tutorials | YouTube >>