comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota@adarose.com>
Subject: Re: Negative float problem
Date: Thu, 03 Nov 2005 18:55:00 GMT
Date: 2005-11-03T18:55:00+00:00	[thread overview]
Message-ID: <82taf.16826$Ul3.8009@trndny07> (raw)
In-Reply-To: <dkd8pd$6rd$1@sunnews.cern.ch>

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"



  reply	other threads:[~2005-11-03 18:55 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-26 18:32 Negative float problem Luke
2005-10-26 19:05 ` Samuel Tardieu
2005-10-26 20:42 ` Robert A Duff
2005-10-27  8:05   ` Robert I. Eachus
2005-10-27 14:48     ` Robert A Duff
2005-10-27 15:07       ` Maciej Sobczak
2005-10-27 15:47         ` Robert A Duff
2005-10-28  8:34           ` Maciej Sobczak
2005-10-29 23:39             ` Brian May
2005-10-30  9:11             ` Dmitry A. Kazakov
2005-10-31  9:46               ` Maciej Sobczak
2005-10-31 14:20                 ` Dmitry A. Kazakov
2005-11-01 11:06                   ` Maciej Sobczak
2005-11-01 14:06                     ` Robert A Duff
2005-11-01 14:46                       ` Martin Dowie
2005-11-01 16:04                         ` Hyman Rosen
2005-11-01 17:19                           ` Martin Dowie
2005-11-02  0:13                         ` Robert A Duff
2005-11-02  6:59                           ` Martin Dowie
2005-11-02 13:24                             ` Robert A Duff
2005-11-02 15:22                               ` Martin Dowie
2005-11-01 15:12                       ` Maciej Sobczak
2005-11-02  0:28                         ` Robert A Duff
2005-11-02  4:16                           ` Steve Whalen
2005-11-14  7:26                           ` Dave Thompson
2005-11-20  0:19                             ` Robert A Duff
2005-11-20 11:07                               ` Dmitry A. Kazakov
2005-11-01 14:27                     ` Dmitry A. Kazakov
2005-11-01 15:19                       ` Maciej Sobczak
2005-11-01 19:44                         ` Dmitry A. Kazakov
2005-11-02  9:04                           ` Maciej Sobczak
2005-11-02 11:17                             ` Dmitry A. Kazakov
2005-11-02 13:03                               ` Maciej Sobczak
2005-11-02 14:20                                 ` Jean-Pierre Rosen
2005-11-02 20:15                                   ` Jeffrey R. Carter
2005-11-03 13:06                                     ` Jean-Pierre Rosen
2005-11-03 18:32                                       ` Jeffrey R. Carter
2005-11-03  9:51                                   ` Maciej Sobczak
2005-11-03 13:20                                     ` Jean-Pierre Rosen
2005-11-03 15:02                                       ` Maciej Sobczak
2005-11-03 18:55                                         ` Frank J. Lhota [this message]
2005-11-04  9:32                                           ` Maciej Sobczak
2005-11-03 20:59                                     ` Simon Wright
2005-11-02 13:32                               ` Robert A Duff
2005-11-02 14:44                                 ` Dmitry A. Kazakov
2005-11-02 13:47                               ` Dmitry A. Kazakov
2005-10-27 18:33       ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox