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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 11:37:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!vixen.cso.uiuc.edu!howland.erols.net!newsfeed.cwix.com!sjc-peer.news.verio.net!news.verio.net!stl-feed.news.verio.net!newsreader.wustl.edu!unlnews.unl.edu!newsfeed.ksu.edu!nntp.ksu.edu!news.okstate.edu!not-for-mail From: David Starner Newsgroups: comp.lang.ada Subject: Re: Integers and Mathematical Correctness Date: 1 Nov 2001 18:54:34 GMT Organization: Oklahoma State University Message-ID: <9rs5pa$8201@news.cis.okstate.edu> References: Reply-To: dstarner98@aasaa.ofe.org NNTP-Posting-Host: x8b4e5494.dhcp.okstate.edu User-Agent: slrn/0.9.7.2 (Linux) Xref: archiver1.google.com comp.lang.ada:15573 Date: 2001-11-01T18:54:34+00:00 List-Id: On Wed, 31 Oct 2001 20:27:16 -0000, chris.danx wrote: > 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 guess this was a big deal in Forth, so "Forth, the New Model" covers it in detail. (It's a nice book, and you can find it for pretty cheap.) Basically, a division is correct if dividend / divisor = quotient, modulus implies that (quotient * divisor) + modulus = dividend But (-2 * 2) + 1 = -3 = (-1 * 2) + -1. The first is division floored to negative infinity, and the second is division symmetric around zero, and either are valid. Forth-83 picked the first, and Ada and Forth-79 picked the second. (ANSI Forth, being a standard, cut the difference and offered operators for both.) -- David Starner - dstarner98@aasaa.ofe.org Pointless website: http://dvdeug.dhis.org "I saw a daemon stare into my face, and an angel touch my breast; each one softly calls my name . . . the daemon scares me less." - "Disciple", Stuart Davis