home *** CD-ROM | disk | FTP | other *** search
- \ Lesson 2 Part 130 ( F-PC 3.5 Tutorial by Jack Brown )
-
-
- \ Well let's use our division to find the area of a triangle.
-
- \ A = bh/2 We'll make a word called AREA ( b h -- ) that has for its
- \ output: Base = xxx Height = xxx Area = xxx
-
- : AREA ( b h --)
- 2DUP SWAP
- CR ." Base = " .
- ." Height = " .
- * 2 /
- ." Area = " . ;
-
- COMMENT:
- Well.... that was fairly simple... and guess what? It wouldn't matter
- whether or not we were using Floored or Symmetric Division the results
- would always be the same. The reason is that the dividend bh and the
- divisor 2 both have the same sign (positive) and as long as the dividend
- and the divisor have the same sign ( both positive or both negative)
- both Symmetric and Floored division give the same results!!!
-
- Now try this version of the triangle area program.
- COMMENT;
-
- : TRIANGLE_AREA ( b h --)
- 2DUP SWAP
- CR ." Base = " .
- ." Height = " .
- * 2 /MOD
- ." Area = " .
- 1 BACKSPACES ( 8 EMIT does not back up cursor in F-PC)
- ASCII . EMIT
- IF ASCII 5 EMIT
- ELSE ASCII 0 EMIT
- THEN ;
-
- COMMENT:
- Problem 2.17.
- a) What do you observe when you use 5 and 3 for the base and height?
- b) What do you observe when you use 5 and 4 for the base and height?
- c) Explain in detail why you get the result you see for question 1.
- d) Could you modify the idea contained in the above to compute the Area
- of a circle to three decimal places? Hint: It can be done quite easily
- and if you can do it you have the potential to become a Forth Super Star!
-
- COMMENT;
-
-
-
-
-
-