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 Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.glorb.com!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Integers and Mathematical Correctness Date: Mon, 29 Sep 2014 18:25:00 +0200 Organization: cbb software GmbH Message-ID: References: <7ab81f91-af1f-4fb1-8aef-c7f692e22f38@googlegroups.com> <72db10f1-7e12-4f8c-8ee5-c2bdce727c09@googlegroups.com> <34da5a39-9fa3-4e8e-a3f9-98f61a4ebcc7@googlegroups.com> <1vtp35phxa6d9$.ni9xlewi7r5v.dlg@40tude.net> <86b50b2e-57ad-47f3-bdaf-b98abcb722be@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ZB2Fb2q1fa4xpMpNKFqV6Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: number.nntp.dca.giganews.com comp.lang.ada:189242 Date: 2014-09-29T18:25:00+02:00 List-Id: On Mon, 29 Sep 2014 07:58:56 -0700 (PDT), Adam Beneschan wrote: > On Sunday, September 28, 2014 12:47:18 AM UTC-7, Dmitry A. Kazakov wrote: > >>> Therefore, any >>> operation that returns a modular type will automatically convert a >>> negative value to the value modulo the modulus. >> >> No. This is a description of some possible implementation of the operation >> based on an integer type. This is not the only one implementation, e.g. >> there exist machine instructions directly implementing modular operations >> for moduli 2**16, 2**32 ... > > I'm not sure we're on the same page... I'm talking about modular types in > Ada, and my statement is taken directly from RM 3.5.4(19). Should probably be rewritten, because it looks in contradiction with 4.5(10) that claims: "The predefined operations on integer types either yield the mathematically correct result or raise the exception Constraint_Error." The mathematically correct result of any modulo K arithmetic operation is an element of the ring {0, 1, ..., K-1} 10 + 10 = 20 is mathematically incorrect for modulo 16 The mathematically correct one is: 10 + 10 = 4 Though, of course 10 + 10 ¡Ý 4 (mod 16) 10 + 10 ¡Ý 20 (mod 16) 10 + 10 ¡Ý 36 (mod 16) 10 + 10 ¡Ý 52 (mod 16) ... [ Elements of the ring can be considered ether numbers { 0, 1, ..., K-1 } or sets of equivalence {{ 0, K, 2K, ... }, { 1, 1+K, 1+2K, ...}, ... , { K-1, 2K-1, 3K-1, ...}} In ether case there is only one correct result, which cannot be "outside the base range." ] > (Of course, it's always possible for a clever optimizing compiler to > generate code that skips a step.) I bet that is the case for Unsigned_64, Unsigned_32 etc. >> I also do not understand how all this might be related to rational numbers, >> which are neither integer nor modular. > > There's no relation. OK -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de