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-Thread: 103376,3b7846f658978a27 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.75.8 with SMTP id y8mr585079wiv.4.1344753904938; Sat, 11 Aug 2012 23:45:04 -0700 (PDT) Path: q11ni88524398wiw.1!nntp.google.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: can Ada give run-time error or warning for integer division with non-zero remainder? Date: Sun, 12 Aug 2012 08:45:03 +0200 Organization: cbb software GmbH Message-ID: <6w1edbm9sq16.1b2o3nufa2r0p.dlg@40tude.net> References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: 9A8bJrx4NhDLcSmbrb6AdA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-08-12T08:45:03+02:00 List-Id: On Sat, 11 Aug 2012 20:14:42 -0500, Nasser M. Abbasi wrote: > In Ada when dividing 2 integers, the result is an integer > with the remainder ignored. Hence 3/2 gives 1 > > ---------------------------------- > with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; > > procedure foo4 is > N : constant integer := 3; > M : integer; > > begin > M := N/2; > put(M); > > end foo4; > -------------------------- > >>gnatmake foo4.adb >>./foo4 > 1 > Now, suppose I want to know that a division between 2 integers > has resulted in nonzero remainder that was thrown away. May be > because my algorithm is meant to work only for even values and > an odd value means there was a bug somewhere and I want to > know about it. It is not integer division then. You could use integer interval division instead: [3, 3] / [2, 2] = [1, 2]. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de