home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / p2_17jb1.seq < prev    next >
Encoding:
Text File  |  1990-04-08  |  814 b   |  27 lines

  1. \ Alternate to Problem 2.17 (d)
  2.  
  3. \ In this solution we use the right justified display operator .R
  4. \ to avoid the use of 1 BACKSPACES which was used to back up over
  5. \ the trailing blank that  .   provides.
  6. \ We have also replaced the phrase  355 * 113 /MOD
  7. \ with the phrase  355 113 */MOD  for a greater range of radii.
  8. \ */MOD   will first multiply by 355 leaving a 32 bit intermediate
  9. \ product and then divide this 32 bit product by 113.
  10.  
  11.  
  12. \ Compute area of a circle to three decimal places.
  13. : CIRCLE_AREA ( r -- )
  14.         DUP * 355 113 */MOD
  15.         ." Area = " 5 .R        \ ( 8 EMIT ) 1 BACKSPACES
  16.         ASCII . EMIT
  17.         5 0  DO
  18.              10 * 113 /MOD 1 .R \ ( 8 EMIT ) 1 BACKSPACES
  19.              LOOP DROP ;
  20.  
  21. : TEST_CIRC ( -- )
  22.        11 1 DO CR I CIRCLE_AREA LOOP ;
  23.  
  24.  
  25.  
  26.  
  27.