Re: floor problems
- To: mathgroup at smc.vnet.net
- Subject: [mg8176] Re: floor problems
- From: murray at math.umass.edu (Murray Eisenberg)
- Date: Mon, 18 Aug 1997 03:06:59 -0400
- Organization: University of Massachusetts, Amherst
- Sender: owner-wri-mathgroup at wolfram.com
Tom (toad at planet.eon.net) wrote: : Hello Mathematica users. : I had a very frustrating time trying to debug some work I was doing in : Mathematica. I finally pared it down to a problem with the Floor : function, and I have illustrated my concern below. I am using M 3.0 and : a Mac computer. Does anyone have any advice or could you tell me if I : am doing something wrong? : Floor[(.7 67 10)] : 469 : Floor[(67 10 .7)] : 468 Mathematica is NOT making a mistake, even though if you simply ask for the products .7 67 10 and 67 10 .7 you get the same output 469. This is an inherent problem with approximate machine arithmetic -- it is NOT associative! And .7 does not have an exact binary representation (no matter how many bits of precision you might want). To see what's happening, you can look at the actual binary representation of the two products. Do $NumberBits[.7 67 10] $NumberBits[67 10 .7] and you will get different results. Evidently, when Mathematica takes the floor (of the binary representation), it therefore gets different results. Welcome to the world of numerical analysis where, as one wit put it, no number that anyone really cares about has ever been calculated exactly. -- Murray Eisenberg Internet: murray at math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Amherst, MA 01003 Fax: 413-545-1801