Related articles |
---|
[11 earlier articles] |
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: | Roger Barnett <Roger@natron.demon.co.uk> |
Keywords: | arithmetic |
Organization: | Natron Software Maintenance Ltd |
References: | 95-04-135 |
Date: | Fri, 28 Apr 1995 19:36:38 GMT |
gsc@magna.com.au writes:
> 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.
Surely the correct approach is for the language definition to state
explicitly what the rules are for truncation, rounding, etc. - then
the programmer knows what to expect in any given situation.
In the extracted text above, if
-1 :/ 2 = -1, { where :/ is integer division )
then
- (-1 :/ 2) = 1 <> 1 :/ 2
which seems counter-intuitive to me.
--
Roger Barnett
Natron Software Maintenance Ltd, York, England
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.