Re: Wrong Precision with "N" ??

*To*: mathgroup at smc.vnet.net*Subject*: [mg24145] Re: Wrong Precision with "N" ??*From*: "P.J. Hinton" <paulh at wolfram.com>*Date*: Wed, 28 Jun 2000 02:12:00 -0400 (EDT)*Organization*: "Wolfram Research, Inc."*Sender*: owner-wri-mathgroup at wolfram.com

On 27 Jun 2000, J.R. Chaffer wrote: > Will someone explain to this newbie why the advertised behavior of the > numerical evaluation function "N" to some specific precision - flatly > ignores the second argument? > > For example, on my machine, > > N[Pi,2] = N[Pi,3] = N[Pi,4] = N[Pi,10] = 3.14159 > > which is not at all what 'Help', and any number of books, claim, with > no explanation of why it just might not work out that way (??) In each of these cases, N[] is really computing Pi to machine precision: In[1]:= {Precision[#], MachineNumberQ[#]} & /@ {N[Pi, 2], N[Pi, 3], N[Pi, 4], N[Pi, 10]} Out[1]= {{16, True}, {16, True}, {16, True}, {16, True}} In the reference guide entry for N[], there is a note warning the user of this: | N[expr, n] may internally do computations to more than n digits of | precision. The number of digits of precision displayed by the front end for machine precision numbers is specified with the option PrintPrecision. The default value is 6, which accounts for the formatting that you're observing. You can increase the number of digits displayed by adjusting PrintPrecision for a notebook or a given cell. Another way to control this from the kernel level is to use SetPrecision[] so that the kernel stores it as an arbitrary precision number. In[2]:= SetPrecision[N[Pi, 10], 10] Out[2]= 3.141592654 The precision is marked internally as ten digits, so the PrintPrecision formatting doesn't apply. In[3]:= {Precision[#], MachineNumberQ[#]} &[%] Out[3]= {10, False} This behavior is touched on briefly in _The Mathematica Book_. You can retrieve this information by pasting the following expression in a notebook and evaluating it. FrontEndExecute[ FrontEnd`HelpBrowserLookup[ "MainBook", {"3.1.4", "4.18"} ] ] More information about PrintPrecision is given here: FrontEndExecute[ FrontEnd`HelpBrowserLookup[ "OtherInformation", "PrintPrecision" ] ] -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.