🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.theory
Article #2090

Re: What if the Divisor is Negative? (was Re: Modulus)

#2090
From: Richard O'keefe
Date: Mon, 26 Feb 1990 07:55
20 lines
1422 bytes
In article <4356@daffy.cs.wisc.edu>, lori@rt7.cs.wisc.edu (Lori Lehman) writes:
[asking about X div Y when Y < 0]

The thing which keeps tripping people up is the assumption that
there is *one* "proper" definition of div and mod.  Common Lisp
offers four:
	(floor x y)    => q r		;; round towards -oo
	(ceiling x y)  => q r		;; round towards +oo
	(truncate x y) => q r		;; round towards 0
	(round x y)    => q r		;; round to nearest (on tie to even)
where in each case x = q*y + r and |r| < |y|
I have had occasion to use _each_ of these functions, and I've been glad
that the names said clearly which one I was using.

It would be useful to have something else, say
	(quotient x y)	=> q r		;; undefined for x < 0 or y <= y
which could do whatever was fastest on a particular machine; the use of
this function would be a signal to the human reader that the arguments
were expected to be in a range where it didn't matter which opcode was
used (usually the case).
Technical Details
Message-ID: <2911@goanna.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok
References: <4356@daffy.cs.wisc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok
From: ok@goanna.oz.au (Richard O'keefe)
Newsgroups: comp.theory,comp.misc,comp.lang.misc
Subject: Re: What if the Divisor is Negative?  (was Re: Modulus)
Message-ID: <2911@goanna.oz.au>
Date: 26 Feb 90 07:55:17 GMT
References: <4356@daffy.cs.wisc.edu>
Followup-To: comp.lang.misc
Organization: Comp Sci, RMIT, Melbourne, Australia
Lines: 20