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


# Search:

In Double-Precision Numeric Display Words in 32-bit library

Word Name: #
Type: Standard word
Data Stack Signature: ud:x – ud:y
Return Stack Signature: --
Availability: V1.2
Description:

Divides the 32 bit stack value by BASE to produce a single digit, which is appended to the Pictured Numeric Output string buffer.

Example:

DECIMAL 123. <# # # # #> TYPE

Taking the above example one 'word' at a time:

  • First, the double value 123 is placed on the stack.
  • <# is executed, which prepares the PNO buffer to receive data.
  • # is executed. This divides the number on the stack (123) by BASE, which has been set to 10 in the above example by means of DECIMAL.
  • The division of 123 by 10 yields a quotient of 12 and a remainder of 3. The remainder (3) is placed in the PNO buffer in ASCII form, and the quotient (12) replaces the value on the stack.
  • # is again executed. This divides the number on the stack (12) by BASE. The division of 12 by 10 yields a quotient of 1 and a remainder of 2. The remainder (2) is placed in the PNO buffer in ASCII form, and the quotient (1) replaces the value on the stack.
  • # is again executed. This divides the number on the stack (1) by BASE. The division of 1 by 10 yields a quotient of 0 and a remainder of 1. The remainder (1) is placed in the PNObuffer in ASCII form, and the quotient (0) replaces the value on the stack.
  • #> is then executed. #> removes the value from the stack, and replaces it with the address and length of the string that has been constructed in the PNO buffer. This address/length pair can be fed directly to TYPE to display the number. At this point, PNO conversion is complete.
  • TYPE is executed, which simply uses the data left on the stack by #> to display the string inside the PNO buffer.

Upon completion of PNO conversion the PNO buffer contains the ASCII characters:

1 2 3

And _PNOLEN contains the length.

Since # performs division, taking the remainder and adding it to the PNO buffer, the order of the conversion proceeds from least significant digit to most significant digit. However, to make things simple for the user, the PNO buffer is populated 'backwards' meaning that the string is actually stored 'forwards' in the PNO buffer, which is why words such as TYPE can be used to display it.

Additional features exist to add characters to the PNO string in order to format the number as desired. See HOLD and INS: for more information.

Comment:

The word # takes a single digit from the unsigned-double number on the stack (it divides the number by the current number base, as determined by BASE) and places this digit into the pictured-numeric-output buffer for display later.

After each invocation of # the value on the stack shall have been divided by the BASE value.

See Also: <#  #> 

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