Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!hplabs!hpfcso!hplisa!hpislx!bayes From: bayes@hpislx.HP.COM (Scott Bayes) Newsgroups: comp.sys.mac.programmer Subject: Re: Why can't the Mac add? Message-ID: <9710005@hpislx.HP.COM> Date: 26 Sep 90 23:43:03 GMT References: <45060@apple.Apple.COM> Organization: Measurement Systems Operation - Loveland, CO Lines: 37 > Let's try this one more time, then I promise to go away and stop > bothering all you nice people. > > I know what happens when you convert 0.2 to binary. I know literally > how precision is lost in the base conversion. I know what a mantissa and > an exponent are. That's not my question. > > I know that the sample program I posted is bad programming style, > but it illustrates the question well. So stop flaming me about it. > (I don't usually write code like that, I promise.) > > huh-HUM (throat clearing noises.) > The calculator DA can do this math correctly. If you add 0.2 fifty > times, you get 10.0. Exactly. Not 9.999999 or 10.0000001. I tried > changing my float variable to an extended, as someone suggested. No dice. > Does the calculator DA have its own special math package? (If so, the > dCad calculator does too.) No one seems to think SANE has calls which > take care of this. So why does it work in the calculator? > > David So does the calculator DA work in base 10, maybe? Note that QuickBASIC for the Mac hase a decimal base version, which should also give exact answers for your case. It's just that often decimal base calculations are considered enough more expensive than binary in a binary computer that they are only used in specialized code, usually. Nice for business, where the world is naturally decimal; not so nice in science, where it only seems to be decimal based, due to the way we write things down. Scott "binary" Bayes Note: the decimal base trick is often done with 2 BCD fields per byte, except in "infinite-precision" math, where it might be done with rational numbers, or strings, or goodness knows what... I believe HP's old 9845 was a decimal base machine. S