Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16330
| From | Richard Fateman <fateman@cs.berkeley.edu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: gives 919.8359999999999?` |
| Date | 2013-12-08 09:35 +0000 |
| Message-ID | <l81ehe$8tc$1@smc.vnet.net> (permalink) |
| References | <l7rtbp$o5b$1@smc.vnet.net> |
| Organization | Time-Warner Telecom |
On 12/5/2013 11:11 PM, Bill Rowe wrote:
..... And this is characteristic is
> inherent in any modern computer.
At least when using double-precision binary floating-point arithmetic.
Which is what Mathematica happens to be using here. It doesn't always.
See below.
>
> If you want to avoid this characteristic in Mathematica, simply
> use exact arithmetic.
That may seem simple, but can lead to exponentially expensive arithmetic.
Compare Timing[Sum[1/n,{n,1,100000];]
to
Timing[Sum[1.0/n,{n,1,100000];]
As for your particular example, you could try this:
FullForm[916.53600000000000000 + 3.300000000000000000000]
which gets all the digits you expect.
Even better you (and other readers of this note) could read
David Goldberg, "What Every Computer Scientist Should Know About
Floating-Point Arithmetic".
That is
>
> In[1]:= 916536/1000 + 33/10
>
> Out[1]= 229959/250
>
> In[2]:= N[%]
>
> Out[2]= 919.836
>
> In[3]:= FullForm[%]
>
> Out[3]//FullForm= 919.836`
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: gives 919.8359999999999?` Bill Rowe <readnews@sbcglobal.net> - 2013-12-06 07:11 +0000 Re: gives 919.8359999999999?` Richard Fateman <fateman@cs.berkeley.edu> - 2013-12-08 09:35 +0000
csiph-web