home *** CD-ROM | disk | FTP | other *** search
- \ Lesson 5 Part 2 examples.
-
- \ Let's use */ to do some percentage calculations. We want to make a word
- \ that finds p % of a number n and leaves the result as m. The stack
- \ picture would be:
-
- \ % ( p n -- m ) where m = p*n/100
-
-
- : % ( p n -- m ) 100 */ ; \ definition using */
-
- : %% ( p n -- m ) * 100 / ; \ defined without using */
-
-
-
- \ Try 32 1820 %% . and 32 1820 % .
- \ Why are the answers different?
-
-
- \ Percentage calculations
-
- \ Use % to find Result Actual
- \ 15 % of 220 33.00
- \ 15 % of 222 33.30
- \ 15 % of 224 33.60
-
- \ Rounding.
- : %R 10 */ 5 + 10 / ;
-
- \ Try %R on the examples above.
-
- \ Leo Brodie's common constants as fractions.
- : *PI 355 113 */ ;
- : *SQRT(2) 19601 13860 */ ;
- : *SQRT(3) 18817 10864 */ ;
- : *E 28667 10546 */ ;
-
- \ Area of circle
- : AREA ( r -- a )
- DUP * *PI ;
-
- \ Volume of sphere
- : VS ( r -- v )
- DUP DUP * * *PI 4 3 */ ;
-
- \ Volume of a cone.
- : VC ( h r -- v )
- AREA SWAP 3 */ ;
-
-
-