Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version)
- To: mathgroup at smc.vnet.net
- Subject: [mg126235] Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version)
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Thu, 26 Apr 2012 05:29:57 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
On 4/23/12 at 5:41 AM, amayer at alum.mit.edu (Alexander Mayer) wrote: >In[1]:= (* This notebook produced by Mathematica 8.0.4.0 *) (* >Platform: OSX 10.6.8 on MacBook Pro *) >In[1]:= b = 6371.01 (* We set the value of b to this real number. *) >Out[1]= 6371.01 >In[2]:= SetPrecision[a = b, 20] (* We test the actual value of b. *) >Out[2]= 6371.0100000000002183 This is not a bug in Mathematica nor is it unique to version 8.0.4. When you enter 6371.01 you are entering a machine precision number that has approximately 16 digits of precision. Since this is a machine precision number, the binary value stored is determined by the FPU in your Mac, not Mathematica. There are several ways to tell Mathematica you want the value 6371.01 to have a precision of 20 digits. The simplest way (in my opinion) is to enter the value like 6371.0`20 An alternative method would be N[637101/100, 20] Either of these methods invokes Mathematica's arbitrary precision arithmetic and the binary bits used to store the value are determined by Mathematica rather than your specific hardware. Additionally, if you are to use SetPrecision to increase the precision of a machine precision number you simply cannot do it using the syntax you tried. That is In[1]:= b = 6371.01; SetPrecision[a = b, 20]; In[3]:= Precision /@ {a, b} Out[3]= {MachinePrecision,MachinePrecision} In[4]:= RealDigits[a] === RealDigits[b] Out[4]= True In[5]:= a = SetPrecision[b, 20]; In[6]:= Precision /@ {a, b} Out[6]= {20.,MachinePrecision} In[7]:= RealDigits[a] === RealDigits[b] Out[7]= False That is SetPrecision does not change the precision of its argument. Instead it returns a value with the requested precision as determined by the argument given.