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
- References:
- Beware of adding 0.0
- From: "paul" <paul_tan@aoI.com>
- Beware of adding 0.0