MathGroup Archive 2004

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

Search the Archive

Re: Beware of adding 0.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50217] Re: [mg50206] Beware of adding 0.0
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sat, 21 Aug 2004 03:04:18 -0400 (EDT)
  • References: <200408200858.EAA12526@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Observe:

$MachinePrecision
SetPrecision[p+SetPrecision[0.0,0],25]
SetPrecision[p+SetPrecision[0.0,1],25]
SetPrecision[p+SetPrecision[0.0,17],25]
SetPrecision[p+0.0,25]

15.9546
3.14159265358979323`25.*^17
3.14159265358979323`25.*^17
3.14159265358979323`25.*^17
3.14159265358979328`25.*^17

Machine precision is MORE than enough to get that last digit correct. (Zero digits of precision is enough, in fact.) But when you're not using SetPrecision to control the precision of 0.0, and you add that to p, p is first changed to machine precision itself so that p+0.0 can be done with machine ARITHMETIC.

Bobby

On Fri, 20 Aug 2004 04:58:00 -0400 (EDT), paul <paul_tan at aoI.com> wrote:

> In Mathematica 5.0, I get a very strange result when I add 0.0 to a number,
> why is this?  See below:
>
> p = SetPrecision[314159265358979323, 25]
> q = SetPrecision[314159265358979323., 25]
> r = SetPrecision[314159265358979323.00000000000000000000, 25]
> s = SetPrecision[p + 0.0, 25]
> {p == q, q == r, r == s, r == p}
> {Tan[s], N[Tan[p]], Tan[q], Tan[r]}
>
>
> \!\(3.14159265358979323`25.*^17\)
> Out[47]=
> \!\(3.14159265358979323`25.*^17\)
> Out[48]=
> \!\(3.14159265358979323`25.*^17\)
> Out[49]=
> \!\(3.14159265358979328`25.*^17\)   *****NOTICE the 28 instead of 23 at the
> end, why does this happen? *******
> Out[50]=
> {True, True, False, True}
> Out[51]=
> {1.599808, -1.12979, -1.1297927, -1.1297927}
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Beware of adding 0.0
  • Next by Date: Re: Beware of NSolve - nastier example
  • Previous by thread: Re: Beware of adding 0.0
  • Next by thread: Re: Beware of adding 0.0