MathGroup Archive 2000

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

Search the Archive

Re: Wrong Precision with "N" ??

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

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:

{Precision[#], MachineNumberQ[#]} & /@ {N[Pi, 2], N[Pi, 3], N[Pi, 4], 
    N[Pi, 10]}

{{16, True}, {16, True}, {16, True}, {16, True}}

In the reference guide entry for N[], there is a note warning the user of

| 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.

SetPrecision[N[Pi, 10], 10]


The precision is marked internally as ten digits, so the PrintPrecision
formatting doesn't apply.

{Precision[#], MachineNumberQ[#]} &[%]

{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.

    {"3.1.4", "4.18"}

More information about PrintPrecision is given here:


P.J. Hinton
Mathematica Programming Group           paulh at
Wolfram Research, Inc.
Disclaimer: Opinions expressed herein are those of the author alone.

  • Prev by Date: RE: Wrong Precision with "N" ??
  • Next by Date: Re: Conditionals with multiple tests?
  • Previous by thread: RE: Wrong Precision with "N" ??
  • Next by thread: Plots with Variable Limits?