Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: Re: SetPrecision vs N

  • To: mathgroup at
  • Subject: [mg71745] RE: [mg71714] Re: SetPrecision vs N
  • From: "David Park" <djmp at>
  • Date: Tue, 28 Nov 2006 06:03:58 -0500 (EST)

The purpose of N is to convert EXACT numbers to approximate numbers with a
given precision. N does nothing whatsoever on approximate numbers. So a
statement like N[1.1, 1000] just leaves 1.1 unchanged.


N[Pi, 50]

does something because Pi is an exact number.

But it appears that SetPrecision works on both approximate and exact

SetPrecision[Pi, 50]

So if one wants to really set the precision of numbers, it is best to use
SetPrecision, and just use N for converting exact to approximate numbers.

David Park
djmp at

David Park
djmp at

From: Peter Pein [mailto:petsie at]

Andrew Moylan schrieb:
> Hi all,
> Suppose I want to evaluate an expression at a given precision. What is
> the difference between using N[expr, precision] and using
> SetPrecision[expr, precision]?
> I've noticed that SetPrecision seems to be equivalent even in such
> situations as e.g. N[Integrate[...]] automatically calling
> NIntegrate[...] when the integral can't be done exactly:
> SetPrecision[Integrate[x^x, {x, 0, 1}], 20]
>   and
> N[Integrate[x^x, {x, 0, 1}], 20]
>   both give
> 0.78343051071213440706
> Are there important differences between SetPrecision and N that I
> should be aware of?
> Cheers,
> Andrew

Hi Andrew,

the most obvious difference is:

Precision[N[1.1, 1000]]
--> MachinePrecision


Precision[SetPrecision[1.1, 1000]]

I guess, SetPrecision[#,prec]& automagically applies N[#,prec]& to an
expression having greater precision than prec (especially when applied to
exact expressions (which got infinite precision)).


  • Prev by Date: Re: Descending order
  • Next by Date: Unexpected warning with ArcTan
  • Previous by thread: Re: SetPrecision vs N
  • Next by thread: Re: Re: SetPrecision vs N