Integer division

Gene Ward Smith gsmith at brahms.BERKELEY.EDU
Thu Jan 30 16:25:12 AEST 1986


In article <11603 at ucbvax.BERKELEY.EDU> weemba at brahms.UUCP (Matthew P. Wiener) writes:
>In article <332 at ism780c.UUCP> tim at ism780c.UUCP (Tim Smith) writes:
>>[Which is preferred: (-a)%b == - (a%b) or (-a)%b >= 0 always?]
>>Are there any good mathematical grounds for choosing one alternative over
>>the other here?  Note that I am not asking from a hardware point of view
>>which is better.  I want to know mathematically if one is better than
>>the other.
>
>I have NEVER seen an instance where the first one is preferable.  Not
>only is it not preferable, it is just incorrect.  Why such a routine
>has been allowed to be 50% inaccurate in every existing language all
>these years is beyond me.
>
>[Whether CS people should even be *allowed* to make such mathematical
>decisions is another question.  In C on UNIX, for example, one has

>ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720

  Matthew has just about said it all, but since this has been my absolute
*pet* gripe for some time now, I can't resist adding another $0.02 to the
bill. When mathematicians define functions in a certain way, it is almost
always for good reasons. I can think of only a few cases where doing 
things differently might be advisable (e.g., 1/Gammma(x) or 1/Gamma(x+1)
instead of Gamma(x) never needs to worry about the poles so might be
better on a computer, even though for theoretical perposes Gamma(x) is
fine). Unless you really understand the situation, don't mess with the
definitions of math functions and we will all be happier. Would CS 
people think |sin(x)| was as good as sin(x), or think that sqrt
should be sqrt(|x|)? Then why mess around with quotient and remainder
functions when you don't have a clue on God's green Earth what you are
doing?


     Signed

     An Angry Number Theorist



More information about the Comp.lang.c mailing list