Re: Integer division specification
On 17 Feb., 20:37, Gennaro Prota <gennaro.pr...@yahoo.com> wrote:
On Wed, 14 Feb 2007 09:25:30 CST, Gennaro Prota wrote:
Hi,
I was wondering if, as part of the synchronization with C99, the C++
standard is going to require truncation towards zero for integer
division or continue to allow the same choice as C90.
Well, let me please do another attempt at getting a reply. I have a
defect report concerning the specification of operator / and the
proposed resolution would depend on whether truncation "towards -inf"
is allowed or not.
It would help everyone, not least the committee which would have to
examine the DR, to know the answer to this (if it is already known
:-)).
I'm sorry, that I can be only of limited help here, but even some
little help is better than nothing, I guess ;-)
I just read the current wording of C99 and the most recent draft for
C++. From what I read, I would deduce the following:
1) C99 (More exactly: I have studied 9899:1999 (E) for this), says
in 6.5.5/6:
"When integers are divided, the result of the / operator is the
algebraic
quotient with any fractional part discarded.87)"
with footnote 87:
"This is often called ''truncation toward zero''."
so indeed C99 demands truncation toward zero.
2) Opposed to this, N2134 says in 5.6/4:
"If both operands are nonnegative then the remainder is nonnegative;
if not, the sign of the remainder is implementation-defined78)"
with footnote 78:
"According to work underway toward the revision of ISO C, the
preferred
algorithm for integer division follows the rules defined in the ISO
Fortran
standard, ISO/IEC 1539:1991, in which the quotient is always rounded
toward zero."
So viewing from the Status Quo I interpret that our C++ Standard does
currently would allow any rounding strategy (including truncation
"towards -inf") if one of the operands is negative.
I cannot say, whether the current state of affairs are by design or
not,
but the synchronization seems to be useful for most programmers.
Greetings from Bremen,
Daniel
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]