Re: Beware of adding 0.0
- To: mathgroup at smc.vnet.net
- Subject: [mg50225] Re: Beware of adding 0.0
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sat, 21 Aug 2004 03:04:38 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 8/20/04 at 4:58 AM, paul_tan at aoI.com (paul) 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] >\!\(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? ******* Look closely at what you are doing, particularly the sequence. You are adding a machine precision number (0.0) to a higher precision number. The precision of this sum will be machine precision. Then you are asking Mathematica to raise the precision of a machine precision number. Once you lose precision by performing the addition you cannot gain it back by using SetPrecision. -- To reply via email subtract one hundred and four