2 ms·
> In C89, division of integers involving negative operands could round upward or downward in an implementation-defined manner; the intent was to avoid incurring
by wahern 7y ago
> In C89, division of integers involving negative operands could round upward or downward in an implementation-defined manner; the intent was to avoid incurring overhead in run-time code to check for special cases and enforce specific behavior. In Fortran, however, the result will always truncate toward zero, and the overhead seems to be acceptable to the numeric programming community. Therefore, C99 now requires similar behavior, which should facilitate porting of code from Fortran to C.
Source: C99 Rationale v5.10 sec. 6.5.5p10 (http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10...)
- bloak 7y agoThanks for that. Now can anyone tell us where the Fortran behaviour came from? (Haskell has both kinds of integer division, called div and quot, which is nice.)