Related articles |
---|
[8 earlier articles] |
Re: Q: division vs multiplication meissner@cygnus.com (Mike Meissner) (1995-04-16) |
Re: Q: division vs multiplication martens@cis.ohio-state.edu (1995-04-16) |
Re: Q: division vs multiplication jmccarty@spdmail.spd.dsccc.com (1995-04-18) |
Re: Q: division vs multiplication leichter@zodiac.rutgers.edu (1995-04-11) |
Re: Q: division vs multiplication kptben@aol.com (1995-04-17) |
Re: Q: division vs multiplication pcg@aber.ac.uk (1995-04-17) |
Re: Q: division vs multiplication gsc@magna.com.au (1995-04-18) |
Re: Q: division vs multiplication jbuck@Synopsys.COM (1995-04-28) |
Re: Q: division vs multiplication davidm@flora.Rational.com (1995-04-28) |
Re: Q: division vs multiplication Roger@natron.demon.co.uk (Roger Barnett) (1995-04-28) |
Re: Q: division vs multiplication jmccarty@spdmail.spd.dsccc.com (1995-04-29) |
Newsgroups: | comp.compilers |
From: | gsc@magna.com.au |
Keywords: | arithmetic, optimize |
Organization: | Compilers Central |
References: | 95-04-080 |
Date: | Tue, 18 Apr 1995 10:21:12 GMT |
martens@cis.ohio-state.edu (Jeff Martens) writes:
>You have to be careful here, though, because a right arithmetic
>shift of an odd negative integer will not give the same result as
>division by 2. For example:
> -1 div 2 is 0
> ashr(-1) is -1
The problem here is that -1 divided by 2 should give -1, with a remainder
of +1. Unfortunately, it's hard to find hardware that does this right.
Most HLLs (even C!) leave division of negative integers to the conscience
of the implementor, though. The obvious solution is to implement division
to round towards -infinity _in all cases_, and you can then use shifts
with a clear conscience.
(Conversely, on a one's complement machine, -1 shifted right is -0. Somehow
I doubt that that would make you feel any better...)
Sean Case
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.