home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / l6p080.seq < prev    next >
Text File  |  1990-04-22  |  2KB  |  72 lines

  1. \ Lesson 6 Part 8  ( F-PC 3.5 Tutorial by Jack Brown )
  2.  
  3. \ A re-definition of Forths Number Display Operators using
  4. \ our modified output formatting words which will allow us
  5. \ to watch their normally transparent operation by setting
  6. \ S&PAD ON .
  7.  
  8. \ Convert an unsigned 16 bit number to a string.
  9. : (U.)  ( un -- addr len )
  10.         0   <# #S #>   ;
  11.  
  12. \ Output as an unsigned single number with trailing space.
  13. : U.    ( un -- )
  14.         (U.)  ( addr len ) TYPE SPACE   ;
  15.  
  16. \ Output as an unsigned single number right justified in a field
  17. \ w wide.
  18. : U.R   ( un w -- )
  19.         >R   (U.)  ( addr len )       \ save w and convert.
  20.         R> OVER -  ( addr len count ) \ count = # of leading spaces
  21.         SPACES   TYPE   ;
  22.  
  23. \ Convert a signed 16 bit number to a string.
  24. : (.)   ( n -- addr len )
  25.         DUP ABS 0
  26.         <# #S   ROT SIGN   #>   ;
  27.  
  28. \ Output as a signed single number with a trailing space.
  29. : .     ( n -- )
  30.         (.)   TYPE SPACE   ;
  31.  
  32. \ .R    Output as a signed single number right justified.
  33. : .R    ( n w -- )
  34.         >R   (.)  ( addr len )       \ save w and convert
  35.         R> OVER - ( addr len count ) \ count = # of leading spaces
  36.         SPACES   TYPE   ;
  37.  
  38. \ Convert an unsigned double number to a string.
  39. : (UD.) ( ud -- addr len )
  40.          <# #S #>   ;
  41.  
  42. \ Output as unsigned double number with a trailing space
  43. : UD.   ( ud -- )
  44.         (UD.)   ( addr len ) TYPE SPACE   ;
  45.  
  46. \ Output as an unsigned double number right justified in
  47. \ a field w wide.
  48. : UD.R  ( ud w -- )
  49.          >R   (UD.)  ( addr len )
  50.          R> OVER -   ( addr len count )
  51.          SPACES   TYPE  ;
  52.  
  53. \ Convert a signed double number to a string.
  54. : (D.)  ( dn -- addr len )
  55.         TUCK DABS       ( sign |dn| )
  56.         <# #S   ROT SIGN  #>  ( addr len ) ;
  57.  
  58. \ Output as a signed double number with a trailing space.
  59. : D.    ( dn -- )
  60.         (D.)  ( addr len ) TYPE SPACE   ;
  61.  
  62. \ Output as a signed double number right justified
  63. \ in a field w wide.
  64. : D.R   ( dn w -- )
  65.         >R   (D.)  ( addr len )
  66.         R> OVER -  ( addr len count )
  67.         SPACES   TYPE   ;
  68.  
  69. ( Please Move to Lesson 6 Part 9 )
  70.  
  71.  
  72.