Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3534
| From | Daniel Lichtblau <danl@wolfram.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Bug 1+4/10 |
| Date | 2011-07-07 11:35 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <iv45lp$f3e$1@smc.vnet.net> (permalink) |
| References | <iv1acv$sk7$1@smc.vnet.net> |
On Jul 6, 4:37 am, "slawek" <sla...@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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Bug 1+4/10 "slawek" <slawek@host.pl> - 2011-07-06 09:37 +0000
Re: Bug 1+4/10 Peter Breitfeld <phbrf@t-online.de> - 2011-07-06 11:06 +0000
Re: Bug 1+4/10 "slawek" <slawek@host.pl> - 2011-07-07 11:41 +0000
Re: Bug 1+4/10 "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-07-07 11:27 +0000
Re: Bug 1+4/10 "slawek" <human@site.pl> - 2011-07-08 08:52 +0000
Re: Bug 1+4/10 "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-07-09 11:41 +0000
Re: Bug 1+4/10 Daniel Lichtblau <danl@wolfram.com> - 2011-07-07 11:35 +0000
csiph-web