Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Bug 1+4/10

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120052] Re: Bug 1+4/10
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 7 Jul 2011 07:30:01 -0400 (EDT)
  • References: <iv1acv$sk7$1@smc.vnet.net>

On Jul 6, 4:37 am, "slawek" <sla... at host.pl> wrote:
> Let check
>
> In[1]:= 1.4 == 1 + 4/10
> Out[1]= True
>
> In[2]:= a = SetPrecision[1.4, 30]
> Out[2]= 1.39999999999999991118215802999
>
> In[3]:= b = SetPrecision[1 + 4/10, 30]
> Out[3]= 1.40000000000000000000000000000
>
> No comment is needed.
>
> slawek

(1) Approximate numbers in Mathematica are internally stored and
manipulated in a binary base.

(2) Given an approximate number, SetPrecision will pad with binary
zeros if requested to set to a precision that is greater than the
precision of the input.

The result Out[2] shown above is a consequence of these.

In a bit (well, a few bits...) more detail:

In[24]:= bits = RealDigits[1.4,2]

Out[24]//InputForm=
{{1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0,
 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 0,
 1, 1, 0}, 1}

In[25]:= morebits = PadRight[bits[[1]], Floor[20*Log[2,10]]]

Out[25]//InputForm=
{1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1,
1, 0,
0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1,
0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

In[26]:= rational = FromDigits[{morebits, bits[[2]]}, 2]

Out[26]//InputForm= 3152519739159347/2251799813685248

In[27]:= N[rational,20]

Out[27]//InputForm=
1.399999999999999911182158029987476766109466552734375`20.

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: How can I get better solution for this...?
  • Next by Date: Re: Unwanted Recursion
  • Previous by thread: Re: Contour ColorFunction in a ParametricPlot
  • Next by thread: Interaction of Remove and Global variables in a Module