MathGroup Archive 2006

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

Search the Archive

Re: SetPrecision vs N


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

vs.

Precision[SetPrecision[1.1, 1000]]
-->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)).

P²


  • Prev by Date: Please help carry out the integral
  • Next by Date: Re: Re: Re: 1`2 == 1*^-10
  • Previous by thread: Re: SetPrecision vs N
  • Next by thread: Re: SetPrecision vs N