MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Decimal math bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28881] Re: Decimal math bug?
  • From: Ignacio Rodriguez <ignacio at sgirmn.pluri.ucm.es>
  • Date: Thu, 17 May 2001 04:22:52 -0400 (EDT)
  • References: <9dlc20$o1r@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Try using Chop. Please understand that Mathematica does not store 1.43
as 143/100 but as a rounded fraction whose denominator is a power of 2.
If you round 1/3 and 2/3 to a decimal 2 digit number, and calculate
1/3+2/3-1, you get 0.33+0.67-1=0. If you calculate 1/3+1/3+1/3-1, you
get 0.33+0.33+0.33-1=-0.01. The same is happening with your approximate
real numbers.

Jim Freeze wrote:

> On Sat, 12 May 2001, Steven M. Christensen wrote:
>
> This looks like a bug.
> Can someone please explain.
>
> This is Mathematica 4.1 (just purchased) on Linux.
>
> In[88]:=(.53+.9) - (1.43) == 0
> Out[88]:=False
> ---------^^^^^
>
> In[89]:=(.53+.9) - (.43+1.0)== 0
> Out[89]:=False
> ---------^^^^^
>
> In[100]:=(.53+.9) - (.43+0.8+0.2) == 0
> Out[100]:=False
> ----------^^^^^
>
> In[102]:=(.53+.9) - (.43+0.8+0.1 +0.1) == 0
> Out[102]:=True
> ----------^^^^
>
> The above results from some strange decimal math:
> In[67]:=Range[.53,4,.9]
> Out[103]:={0.53, 1.4300000000000002, 2.33, 3.23}
>
> where sometimes 1.4300000000000002 == 1.43 and sometimes
> it doesn't.
>
> It is really disconcerting to have that trailing 2.
>
> Can someone please explain what is going on here?
>
> Thanks
> =========================================================
> Jim Freeze
> jim at freeze.org
> ---------------------------------------------------------
> No comment at this time.
> http://www.freeze.org
> =========================================================

--

Ignacio Rodriguez Ramirez de Arellano
Unidad de RMN
Universidad Complutense
Paseo Juan XXIII, 1
Madrid 28040, Spain

Tel. 34-91-394-3288
Fax  34-91-394-3245
e-mail: ignacio at sgirmn.pluri.ucm.es





  • Prev by Date: Re: NIntegrate with floating point limits
  • Next by Date: Re: Names[] for definitions in the current window/notebook?
  • Previous by thread: Re: Decimal math bug?
  • Next by thread: Det[]