integer division in ANSI C

Snoopy seifert at hammer.UUCP
Wed Mar 5 05:46:28 AEST 1986


In article <695 at sftig.UUCP> danny at sftig.UUCP (L.Rosler) writes:

>System programmers really are not concerned about the behavior
>when a negative number is involved.  Except perhaps for -1,
>negative numbers are considered harmful in this arena.  The
>goal of division is to get the positive quotient or positive
>remainder as fast as the hardware can give it, and this will
>always be hardware-independent.
>
>Application programmers, on the other hand, ARE concerned about
>portable division involving negative numbers, a need which C
>does not address.  When this was discussed (at many Standards
>meetings), the following positions emerged:
>
>1.  Ignore the problem -- reliable application programs are
>    not important.
>2.  Force the compiler to generate code to produce portable
>    semantics -- fast systems programs are not important.

[ various other options ]

How about:

case 1:
(unsigned) / (unsigned)  generates the positive quotient as fast as possible

case 2:
one or both are (signed) generates the correct signed quotient

The compiler knows whether the integers are (signed) or (unsigned)
at compile time, and can choose the appropriate code.

Seems like this would satisfy both camps.

Snoopy
tektronix!tekecs!doghouse.TEK!snoopy



More information about the Comp.lang.c mailing list