6.20.2 String to number conversion

>number ( ud1 c-addr1 u1 – ud2 c-addr2 u2  ) core “to-number”

Attempt to convert the character string c-addr1 u1 to an unsigned number in the current number base. The double ud1 accumulates the result of the conversion to form ud2. Conversion continues, left-to-right, until the whole string is converted or a character that is not convertable in the current number base is encountered (including + or -). For each convertable character, ud1 is first multiplied by the value in BASE and then incremented by the value represented by the character. c-addr2 is the location of the first unconverted character (past the end of the string if the whole string was converted). u2 is the number of unconverted characters in the string. Overflow is not detected.

For higher-level integer-to-number conversion (with number prefixes, group separators (_), and double indicators (.), use rec-number (see Default recognizers).

convert ( ud1 c-addr1 – ud2 c-addr2  ) gforth-obsolete

OBSOLETE: This word has been de-standardized in Forth-2012. It is superseded by >number.

>float ( c-addr u – f:... flag ) floating “to-float”

Actual stack effect: ( c_addr u – r t | f ). Attempt to convert the character string c-addr u to internal floating-point representation. If the string represents a valid floating-point number, r is placed on the floating-point stack and flag is true. Otherwise, flag is false. A string of blanks is a special case and represents the floating-point number 0.

You can alternatively use rec-float (see Default recognizers), which accepts a smaller set of input strings: >float is used for known-FP-data possibly coming from another program with funny output syntax and is therefore more liberal in accepting input, while the strings that the text interpreter passes to rec-float are not all intended to be interpreted as FP numbers, and therefore rec-float is more restrictive.

>float1 ( c-addr u c – f:... flag ) gforth-1.0 “to-float1”

Actual stack effect: ( c_addr u c – r t | f ). Attempt to convert the character string c-addr u to internal floating-point representation, with c being the decimal separator. If the string represents a valid floating-point number, r is placed on the floating-point stack and flag is true. Otherwise, flag is false. A string of blanks is a special case and represents the floating-point number 0.