Re: Q: division vs multiplication

jbuck@Synopsys.COM (Joe Buck)
Fri, 28 Apr 1995 19:06:31 GMT

          From comp.compilers

Related articles
[9 earlier articles]
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)
| List of all articles for this month |
Newsgroups: comp.compilers
From: jbuck@Synopsys.COM (Joe Buck)
Keywords: arithmetic, optimize
Organization: Synopsys Inc., Mountain View, CA 94043-4033
References: 95-04-003 95-04-080
Date: Fri, 28 Apr 1995 19:06:31 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


Doesn't this thread recycle every six months or so? The first statement
is only a convention, true on some but not all processors, and not a very
good one at that (for many types of signal processing, defining division
as truncate-toward-zero is a mistake, as it introduces a bias in the data:
uniformly distributed integers are no longer uniformly distributed after
division, instead 0 becomes more likely than other values). It's not even
a standard in many cases: C does not promise that -1/2 is 0; it could also
be -1. C only promises consistency between "/" and "%". If your programs
assume -1/2 is 0, then they are non-portable.




--
-- Joe Buck <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
Phone: +1 415 694 1729
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.