Architecture of Integer Remainder

Frank Adams franka at mmintl.UUCP
Wed Mar 5 08:47:29 AEST 1986


In article <9341 at ucla-cs.ARPA> jimc at ucla-cs.UUCP writes:
>   When a negative integer is divided, what should be the sign of the
>remainder?
>   "C" users: Do we have a consensus that there should be a specific standard,
>and that we want the remainder sign positive -- if the efficiency issue can
>be resolved?  Do users want a positive remainder even if it usually means
>wasted code?  How do users of other languages feel?

If the efficiency issue could be resolved, this would be a good idea.
Unfortunately, it cannot be.  Some of the architectures in use now will
still be in use 20 years from now.  (Some of the architectures in use 20
years ago are still in use now.)  This is too long a time frame to
standardize in.

>   Compiler writers: Is it feasible to recognize when a dividend is in fact
>always positive, so the extra code can be omitted?  If you declare the
>dividend explicitly unsigned, on some machines you must produce bizarrely
>contorted code to handle the N'th bit; is it feasible to recognize when these
>contortions are unnecessary?

In a word, no.  One can do this for some of the cases, but not in general.
I suspect not even in a majority of the cases can this be done.


I would recommend that C keep the / and % operators as they are now.
One might add new operators which specify which result is wanted, but
this is not the sort of thing the current ANSI committee should be
looking at -- save the enhancements until we have a standard.

Frank Adams                           ihnp4!philabs!pwa-b!mmintl!franka
Multimate International    52 Oakland Ave North    E. Hartford, CT 06108



More information about the Comp.lang.c mailing list