Hmm, I hope this is exported, or that Martin reads the lyskom conference.
Basically, I want (a + b*n) / n == a/n + b to hold. That means that the graph of the function f(x) = x/n should look something like
--- --- --- --- --- --------------------> x
A stair where all the steps are of the same shape. That is what you get if you always round downwards (or always upwards, but that's not an option). With round towards zero, you get one special step in the middle, like
--- --- ------ --- ---
Further properties that I'd like to hold are
a == b*(a/b) + a % b
(this one is actually guaranteed by c89 ANSI-C, I think), which is why the behaviour of % and / are interlinked.
And I want that, for n > 0, that a % n >= 0 for all n. That means that
arr[x % sizeof(arr)]
will never give you a range error (except if sizeof(arr) == 0), no matter how large or small x is.
/ Niels Möller ()
Previous text:
2003-01-15 14:45: Subject: Re: signed integer division
On Wed, Jan 15, 2003 at 01:45:03PM +0100, Johan Sundström (a hugging punishment!) @ Pike (-) developers forum wrote:
Excellent documentation material for `/ and `%, Niels; thanks. I'm taking the liberty of incorporating parts of that discussion to the refdocs.
not being a mathematician, could someone give some examples that demonstrate the braindamage of the rounding towards 0 way?
greetings, martin.
interested in doing pike programming, sTeam/caudium/pike/roxen training, sTeam/caudium/roxen and/or unix system administration anywhere in the world. -- pike programmer working in europe csl-gmbh.net open-steam.org (www.archlab|(www|db).hb2).tuwien.ac.at unix bahai.or.at iaeste.(tuwien.ac|or).at systemadministrator (stuts|black.linux-m68k).org is.(schon.org|root.at) Martin Bähr http://www.iaeste.or.at/~mbaehr/
/ Brevbäraren