Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: PYGMY Forth Message-ID: <1554.UUL1.3#5129@willett.pgh.pa.us> Date: 20 Aug 90 00:41:30 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 97 Category 1, Topic 45 Message 35 Sun Aug 19, 1990 F.SERGEANT [Frank] at 13:25 CDT To Chris Waters 2 of 2 CW>I haven't seen BASIS yet ... Ghod I hope they gave up on floored CW>division. :) All of this is just an introduction to a discussion of floored vs zero'd division. I believe that the way it currently stands they require two new words, one for each way, and you define / etc in your application to use the method you choose. I've recently been pouring over Knuth's book and Roedy Green's assembly listing on division and thinking about and worrying over division. The one thing I've learned is that I ain't never gonna be a mathematician. I believe that in the history of man's mathematical progress there was a very long period of time before negative numbers were accepted. Now we have no (little?) trouble grasping them. Now let's take division. When all the numbers are positive integers and we want a quotient and remainder we are all agreed. The quotient is "floored" (if the real quotient is not an integer, the lower of the two integers it falls between is chosen) and it is also "truncated toward zero" (of those same two integers, the one nearest to zero is chosen). The remainder is the positive integer difference between the dividend and the product of the chosen integer quotient and the integer divisor. What could be simpler? If we want only a quotient (no remainder), and the real quotient is not an integer, the problem is more complex. Do we take the floor or the ceiling or round according to some particular formula (and there are several to choose from)? I think we are generally agreed that we either take the floor (which is also the zero'd) or that we round somehow. It is only we start to consider negative dividends and or negative divisors that things really go to hell. What does it even MEAN to divide negative numbers? I don't know. I can go back to accounting analogies and consider a negative amount to be money I owe and a positive number to be money I have. Consider 5 partners who owe a thousand dollars. Each partner's share would be -1000 5 / so I can wrap my mind around division involving a negative dividend. Suppose there were only 3 partners. -1000 3 / now we need /MOD fer sure. Is each one's share -333 with a -1 left over? Or, is each one's share -334 with a +2 left over? I think we are in the realm of philosophical questions here. As an accountant I'd say, "cough up $333.33 each and I'll pay the extra penny!" (Accountants are happy to write off many dollars to make things come out even, a mere penny would be completely inconsequential.) So, I can see dividing a positive or a negative number by a positive number, but have not been able to fully wrap my mind around the idea of dividing by a negative number. What does it MEAN? (It probably means nothing unless you need to do it for a specific purpose, at which point you know what it means.) Many months ago I suggested that flooring negative quotients ( -1000 3 / --> -334 ) didn't feel right. It didn't correspond to my "grade school" understanding and every day familiarity. I suggested a solution: treat negative numbers like we (and I use "we" loosely!) treat square roots of negative numbers. We handle these by factoring out that troublesome -1. We find its square root separately (and by definition call it "i") and then are left with the familiar problem of finding a square root of a positive number. I liked (and still like) the idea of factoring out the -1s from the dividend and divisor so that we are doing division with positive numbers (where there is no particular controversy). Thus, -1000/3 would be treated as (-1)( 1000/3) and -1000/-3 would be (-1)(-1)(1000/3) So, we really only need division of positive numbers by positive numbers. (I'm not saying this solves any problems - just that it is a comforting way for me to look at it.) Remember, when it comes to floored vs zero'd, there is no difference at all for positive numbers and no difference at all when the real quotient is an integer. It only matters when one or both of the operands is negative, and then only if there is a remainder. In working over some higher precision division words, I was prepared to try flooring. Not because I think it is superior, but because Robert Berkey thinks it is superior (I think) and because he understands it better than I do. However, as I looked it over more & more, I stayed dissatisfied with having -1000 3 / give -334 with a +2 remainder. I think my applications involving negative numbers are much more likely to concern negative dollars or positive dollars divided by a positive number. In such a case, I think it is unfair discrimination (I fully support accurate, just discrimination) to treat the numbers on one side of a balance sheet as different from those on the other side. So, I want -1000 3 / to give -333 with a -1 left to be dealt with and 1000 3 / to give +333 with a +1 left to be dealt with. I hear you need floored with negative operands in order to control stepper motors without them jerking. This makes no sense to me. Drive 'em from a table; drive 'em always with either +1 or -1 till a feedback switch goes true; scale the -10 -9 -8 ... -1 0 +1 +2 ... +9 +10 up to 0 1 2 3 ... 18 19 20 - so what's the problem? As always, maybe I'll learn more in the future and see the need for floored division instead of zero'd. -- Frank ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us