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

  1. \ Problem 5.4    Dan Dubrick    Set 14D4
  2.  
  3. \ Rounded percent calculations
  4. : %R1 ( p n -- m ) 10 */  5 + 10 / ;
  5. : %R2 ( p n -- m ) 50 */  1+ 2/ ;
  6. : %R3 ( p n -- m ) 100 */MOD SWAP 50 + 100 / + ;
  7. : %R4 ( p n -- m ) 100 */MOD SWAP 59 > NEGATE + ;
  8.  
  9. VARIABLE TIME1
  10. VARIABLE TIME2
  11. VARIABLE TIME3
  12. VARIABLE TIME4
  13.  
  14. \ Timer loop to test all four rounded percent calculations
  15. : TIME_FOUR ( -- )
  16.       CR ." This is definitely going to take a while, as all four"
  17.       CR ." rounded percent calculations are tested in four loops. "
  18.       TIME-RESET
  19.       1000  0 DO  1000 0 DO
  20.               \ blank loop
  21.                 15 224 %R1 DROP
  22.               LOOP LOOP
  23.       CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R1 pass."
  24.       TIME-RESET
  25.       1000  0 DO  1000 0 DO
  26.               \ blank loop
  27.                 15 224 %R2 DROP
  28.              LOOP LOOP
  29.       CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R2 pass."
  30.       TIME-RESET
  31.       1000  0 DO  1000 0 DO
  32.               \ blank loop
  33.                 15 224 %R3 DROP
  34.               LOOP LOOP
  35.       CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R3 pass."
  36.       TIME-RESET
  37.       1000  0 DO  1000 0 DO
  38.               \ blank loop
  39.                 15 224 %R4 DROP
  40.               LOOP LOOP
  41.       CR TIME-ELAPSED B>SEC . 230 EMIT ." -Seconds for one %R4 pass."
  42.       CR ;
  43.  
  44. \ The fastest of the four calculations by the elapsed time is %R4.
  45.  
  46.