MathGroup Archive 2012

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

Search the Archive

Re: Serious Bug in Mathematica 7 and (latest version)

On 4/23/12 at 5:41 AM, amayer at (Alexander Mayer) wrote:

>In[1]:= (* This notebook produced by Mathematica *) (*
>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


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


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.

  • Prev by Date: NonlinearModelFit and Complex Data
  • Next by Date: Re: About linear programming
  • Previous by thread: Re: Serious Bug in Mathematica 7 and (latest version)
  • Next by thread: Question about DayOfWeek