home *** CD-ROM | disk | FTP | other *** search
- ╔════════════════════════════════════════════════════╗
- ║ Lesson 2 Part 100 F-PC 3.5 Tutorial by Jack Brown ║
- ╚════════════════════════════════════════════════════╝
-
- ┌─────────────────────────────────────────────────────┐
- │ We continue with exerpts from R.L. Smith's article: │
- └─────────────────────────────────────────────────────┘
-
- The following are the same plots for Floored integer division:
-
- 10q
- FLOORED q vs m + Divisor = n = 3
- +
- +
- +
- + o
- + o o o
- + o o o
- + o o o
- -10 + o o o 10
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-o-o-o-+-+-+-+-+-+-+-+-+-+-+-+-+m
- o o o +
- o o o +
- o o o +
- o o o +
- o o o +
- +
- +
- + m = nq + r
- + m/n = q + r/n
- -10
- Quotient vs Dividend for Floored Integer Division
- ( m = dividend, n = divisor, q = quotient, and r = remainder)
-
- [ note that the large step near the origin no nonger exists. jwb ]
-
- 10r
- FLOORED r vs m + Divisor = n = 3
- +
- +
- +
- +
- +
- +
- o o o o o + o o o o o
- o o-10 o o o + o o o o o
- o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o-+-+-o m
- + 10
- +
- +
- +
- +
- +
- +
- + m = nq + r
- + m/n = q + r/n
- -10
- Remainder vs Dividend for Floored Integer Division
- ( m = dividend, n = divisor, q = quotient, and r = remainder)
-
- [ Note that the remainder is cyclical for both negative and
- positive dividends jwb ]
-
- R.L. Smith continues....
-
- Floored division is simply more useful in the majority of application
- programs. The major objection is that the results are not what most
- people expect: -1 divided by 4 gives 0 in the rounded toward zero
- division case [Symmetric division jwb] , but -1 for Floored division.
- Both cases give the same results when the dividend and divisor have the
- same sign.....
-
- The above is only an exerpt from Smiths article, see DDJ for the
- complete discussion.
-
- We found R.L. Smiths division plots very informative in helping to
- understand Floored vs Symmetric division. The only problem was that
- there were not enough charts!. We would like to see a chart for
- negative divisors so instead of constucting a chart for just one
- negative divisor we have written a progaram which will let you choose
- any positive or negative divisor between -10 and +10 and the program
- will construct the charts for you. The end user word in the program is:
-
- INTDIV ( n -- ) \ Where n is the divisor.
-
- The following message has the results of executing:
-
- -4 INTDIV <enter>
-
- The only new word used in the program is the cursor positioning word AT
-
- AT ( x y -- ) \ x is the horizontal position, y is the vertical.
- \ 0 0 is the upper left corner 80 22 is the lower right.
-
- We threw this program together fairly quickly and it is not the best
- example of programming. You might like to write an improved version
- that includes a bit more factoring of some of the common program
- phrases.
-
- ┌──────────────────────────────────┐
- │ Please move to Lesson 2 Part 110 │
- └──────────────────────────────────┘
-