int divided by unsigned.

Jim Giles jlg at lanl.gov
Mon Jun 19 06:30:35 AEST 1989


>From article <748 at sdrc.UUCP>, by scjones at sdrc.UUCP (Larry Jones):
> [...]
> Well, there're two good reasons why you DON'T want to promote to
> long:  long might well be the same size as int and, if it's not,
> it may well take a lot longer to compute the answer.  In the
> first case, you get an answer which is no more useful than the
> unsigned version, [...

This is not true.  If long is the same as int, then I would at least
get signed arithmetic performed.  So, in my original example, -5/1000
would equal 0.  In fact, 'promoting' unsigned to int would be better
than the other way around.  Since most arithmetic is not carried out
on "large" numbers, promoting to int would produce expected results
more often than the other way around.

> ...]              in the second case you violate the Spirit of C
> by doing non-obvious things behind the programmer's back.

But you are _already_ doing that by casting everything to unsigned!
The point of my submission was that -5/1000 == bignumber _IS_ a non-
obvious thing.  The point is that the default 'promotion' order is
has been poorly defined.



More information about the Comp.lang.c mailing list