6.2.0210 .R dot-r CORE EXT

( n1 n2 -- )

Display n1 right aligned in a field n2 characters wide. If the number of characters required to display n1 is greater than n2, all digits are displayed with no leading spaces in a field as wide as necessary.

See:

Rationale:

In .R, "R" is short for RIGHT.

ContributeContributions

EricBlakeavatar of EricBlake [403] Possible reference implementationSuggested reference implementation2025-08-18 12:10:38

This implementation requires SPACES to gracefully ignore negative input; although it has been questioned whether that is intended by the standard: https://forth-standard.org/standard/core/SPACES#contribution-337. Note that this implementation does not use S>D; doing so would produce the wrong results on a twos-complement machine for the minimum integer value.

: .R ( n1 n2 -- ) \ "dot-r"
  SWAP DUP >R ABS 0 <# #S R> SIGN #> ( n2 c-addr u )
  ROT OVER - SPACES TYPE
;

EricBlakeavatar of EricBlakeNew Version: Possible reference implementation

Hide differences

This implementation requires SPACES to gracefully ignore negative input; although it has been questioned whether that is intended by the standard: https://forth-standard.org/standard/core/SPACES#contribution-337. Note that this implementation does not use S>D; doing so would produce the wrong results on a twos-complement machine for the minimum integer value.

: .R ( n1 n2 -- ) \ "dot-r"

SWAP DUP >R ABS 0 <# #S R> SIGN #> ( n2 c-addr u )

SWAP DUP ABS 0 <# #S ROT SIGN #> ( n2 c-addr u )

ROT OVER - SPACES TYPE ;


Reply New Version