[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: barmar@think.com*Subject*: ROUNDing*From*: andy@chestnut.com (Andy Latto)*Date*: Fri, 28 Jun 1991 11:30:21 -0400*Cc*: JGA@alderaan.scrc.symbolics.com, slug@ai.sri.com*In-reply-to*: Barry Margolin's message of Thu, 27 Jun 1991 18:50-0400 <19910627225033.2.BARMAR@occam.think.com>

> Date: Thu, 27 Jun 1991 18:50-0400 > From: barmar@Think.COM (Barry Margolin) > However, I happened to pick up a copy of Knuth later in the afternoon, > and found the section where he talks about rounding (Seminumerical > Algorithms, section 4.2.2). I couldn't find many details, but at one > point he said that the "right" way to round a number that is exactly > half-way between two units depends on the radix -- if it's even you > round towards the even number, if it's odd you round towards the odd > number. Then he pointed out that all the commonly-used bases are even, > so it's simplest to remember that rounding should be towards the even > number. I don't believe this, even if it's in Knuth. Rounding is an issue to do with numbers, not with numerals. If I ask you whether (round 1/2) is 0 or 1, how can the answer depend on what base I am using? What if I am using Roman Numerals? Or just tally marks, instead of radix notation? As far as I can see "round to an integer divisible by two" and "round to an integer not divisible by two" are equally good rules for rounding <integer> + 1/2. There may be a reason I don't see for preferring even over odd, or maybe it's just convention. But I can't believe that "round to a number whose last digit in your preferred radix has the same parity as the radix" is as good a rule. If you use an odd radix internally, evenp and oddp might be expensive operations compared to last-digit-even-p and last-digit-odd-p. If so, and you want round to be faster than evenp and oddp, it might be that round-to-odd-last-digit is better than round-to-even-last-digit if those are your choices, but there's still nothing wrong with round-to-even. Andy Latto andy@chestnut.com

**Follow-Ups**:**ROUNDing***From:*barmar@Think.COM (Barry Margolin)

**References**:**ROUNDing***From:*barmar@Think.COM (Barry Margolin)

- Prev by Date:
**disks: Symbolics' can't handle power outage?** - Next by Date:
**Re: formating a disk** - Previous by thread:
**ROUNDing** - Next by thread:
**ROUNDing** - Index(es):