From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b61052ba3fdc8c26 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-01 09:53:20 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!netnews.com!xfer02.netnews.com!news.voicenet.com!nntp.upenn.edu!msunews!sens-a.cse.msu.edu!meinersc From: Chad Robert Meiners Newsgroups: comp.lang.ada Subject: Re: Integers and Mathematical Correctness Date: Thu, 1 Nov 2001 12:52:29 -0500 Organization: Michigan State University Message-ID: References: <1f26o22.1xfvwvo111pfi4N%csampson@inetworld.net> <_lfE7.52002$a14.6154112@news6-win.server.ntlworld.com> NNTP-Posting-Host: sens-a.cse.msu.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <_lfE7.52002$a14.6154112@news6-win.server.ntlworld.com> Xref: archiver1.google.com comp.lang.ada:15558 Date: 2001-11-01T12:52:29-05:00 List-Id: On Thu, 1 Nov 2001, chris.danx wrote: > > "Charles Sampson" wrote in message > news:1f26o22.1xfvwvo111pfi4N%csampson@inetworld.net... > > chris.danx wrote: > > > > > Hi, > > > > > > To most this may seem insignificant but I'm more mathematically minded > and I > > > just found something out. Many programming languages don't implement > > > division properly! > > > > > > For example -3/2 should be -2 not -1, with a remainder 1 not -1. > > > > > > I'm trying to implement integer division the "proper" way (according to > > > Euclid), just for fun (and to provide a mathematically correct package > for > > > anyone who gets annoyed by this). > > > > I'm not sure how you determined that the "proper" definition of > > integer division is to return floor (a/b), where "/" is mathematical > > division. The definition used by most programming languages preserves > > the very useful property -(a/b) = (-a)/b = a/(-b), where this time "/" > > represents integer division. > > > > Please explain the Euclid reference. I don't have any History of > > Mathematics books available, but I don't remember that Euclid had nega- > > tive numbers to work with. > > According to Euclid, the "division algorithm" (which isn't an algorithm) > asserts that for a/b > > a = kb + r > > where r >= 0 > k <- Integers Shouldn't it be where 0 <= r < b K <- Integers otherwise k could be -3 and r would then be 5. -CRM