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,9ce095aba33fe8d0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny07.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Reply-To: NOSPAM.lhota@adarose.com User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Negative float problem References: <1130351574.313991.229420@g14g2000cwa.googlegroups.com> <10mspnley7gzu$.1swtj67sv0ldr$.dlg@40tude.net> <38tcpxwxfigo$.18ysjyp9ml92c$.dlg@40tude.net> <2ybc7t4au7g$.166dxwfrds1so$.dlg@40tude.net> <18nrnlg9zzl5a.k8rl3ajwauqi.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <82taf.16826$Ul3.8009@trndny07> Date: Thu, 03 Nov 2005 18:55:00 GMT NNTP-Posting-Host: 151.203.236.121 X-Complaints-To: abuse@verizon.net X-Trace: trndny07 1131044100 151.203.236.121 (Thu, 03 Nov 2005 13:55:00 EST) NNTP-Posting-Date: Thu, 03 Nov 2005 13:55:00 EST Xref: g2news1.google.com comp.lang.ada:6155 Date: 2005-11-03T18:55:00+00:00 List-Id: Maciej Sobczak wrote: > Jean-Pierre Rosen wrote: > >> For example, try to find what "%" does in C/C++ (with at least one >> negative operand, of course)... > > > For fundamental types, this always holds (except when b is 0): > > a == (a / b) * b + a % b > > If any of a or b is negative, then the sign of a % b is > implementation-defined. > > (for user-defined types - like MySuperSafeIntegerWithLotsOfChecks - it's > of course whatever you invent it to be) > > I have to admit that I was never concerned with this rule, I just don't > divide modulo negative numbers - this kind of operation simply has no > meaning in any of the domains where I used C/C++. There are applications, however, where negative integers are divided and remaindered. If such applications are moved to a platform where "/" and "%" are handled differently, portability time bombs are likely to be exposed. Fortunately, this issue has been addressed by the C standards folks, and the C99 standard specifies that integer division must round to 0. This should make Ada fans happy, since the Ada standard required this since 1983. Moreover, C99 requires that "%" behaves like "rem". The bad news is that there are few C99 compilers, due to the rapid switch to C++. The C++ standard needs to be revised to address this issue. All of the C++ compilers I have used round to 0. Are there any C++ compilers in current use that do NOT round to 0? -- "All things extant in this world, Gods of Heaven, gods of Earth, Let everything be as it should be; Thus shall it be!" - Magical chant from "Magical Shopping Arcade Abenobashi" "Drizzle, Drazzle, Drozzle, Drome, Time for the this one to come home!" - Mr. Lizard from "Tutor Turtle"