home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / pr5_3dd.seq < prev    next >
Text File  |  1990-04-19  |  1KB  |  39 lines

  1. \ Problem 5.3    Dan Dubrick    Set 14D4
  2.  
  3. \ Brute force approach to fractions.
  4. \ Display decimal equivilant of fraction m/n
  5. : .XXX ( m n -- )
  6.       2DUP > ABORT" Improper fraction." \ require m < n
  7.       >R 2000 R> */ 1+ 2/       ( Scale and round fraction )
  8.       ASCII . EMIT DUP 10 <
  9.       IF ASCII 0 DUP EMIT EMIT
  10.       ELSE DUP 100 <
  11.                IF ASCII 0 EMIT
  12.                THEN
  13.       THEN . ;
  14.  
  15. \ Print the decimal equivallent if mixed fraction i+m/n
  16. : I.XXX  ( i m n -- )
  17.        ROT 5 .R .XXX ;
  18.  
  19. \ Display decimal equivalents of 1/n through n-1/n
  20. : TEST ( n -- )
  21.       CR DUP 1
  22.       ?DO  CR I OVER  2DUP SWAP
  23.            . ." /" . ." = " .XXX
  24.       LOOP DROP ;
  25.  
  26. \ Calculate the area of a circle and display to three decimal places.
  27. : SPHERE_AREA ( r -- )
  28.       DUP 4 * * 355 113   \ The ratio for pi
  29.       */MOD  SWAP 113     \ Remainder for I.XXX
  30.       ." The area of the sphere is " I.XXX ;
  31.  
  32. \ Calculate the volume of a cone and display to three decimal places.
  33. : CONE_VOLUME ( h r -- )
  34.       DUP * * 3 / 355 113   \ The ratio for pi
  35.       */MOD  SWAP 113       \ Remainder for I.XXX
  36.       ." The area of the sphere is " I.XXX ;
  37.  
  38.  
  39.