Two Birds with One Stone

Lennart Augustsson augustss at chalmers.UUCP
Mon Dec 23 13:19:56 AEST 1985

In article <864 at kuling.UUCP> thomas at kuling.UUCP (Thomas H{meenaho) writes:
>However most useable processors provide arithmetic shifts which will give
>the right result even if it is a signed divide.

Replacing a divide with a signed shift doesn't solve the problem.  Consider
the following:
    decimal                             binary
    -1 / 2  = 0                         11111111 / 10 = 00000000
    -1 >> 1 = -1                        11111111 >> 1 = 11111111

Most machines behave like this when dividing, i.e. they divide the absolute
value of the operands and then sets the correct sign.  There are machines
(e.g. NS 32000) which provide a divide instruction with the other behaviour.

Any resemblance of the opinions above to real opinions, living or dead,
is purely coincidential.
	Lennart Augustsson
UUCP:		{seismo,philabs,decvax}!mcvax!enea!chalmers!augustss
ARPA,CSnet:	augustss at chalmers.csnet

More information about the Comp.lang.c mailing list