Re: Beware of adding 0.0
- To: mathgroup at smc.vnet.net
- Subject: [mg50212] Re: [mg50206] Beware of adding 0.0
- From: stephen layland <layland at wolfram.com>
- Date: Sat, 21 Aug 2004 03:04:13 -0400 (EDT)
- References: <200408200858.EAA12526@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
so spake paul [2004.08.20 @ 04:48]: > 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] 0.0 has $MachinePrecision. You can't expect p (with precision 25) + 0.0 (precision 15.9...) to have automatically have 25 digits of precision... In[5]:= Precision/@{p, 0.0} Out[5]= {25., MachinePrecision} In[6]:= Precision[p+0.0] Out[6]= MachinePrecision The correct method should be: In[7]:= t = p + SetPrecision[0.0, 25]; Precision[t] Out[8]= 25. -ste\/e -- /*-----------------------------*\ | stephen layland | | Technical Support Engineer | | layland at wolfram.com | \*-----------------------------*/
- References:
- Beware of adding 0.0
- From: "paul" <paul_tan@aoI.com>
- Beware of adding 0.0