Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version)

*To*: mathgroup at smc.vnet.net*Subject*: [mg126204] Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version)*From*: DrMajorBob <btreat1 at austin.rr.com>*Date*: Wed, 25 Apr 2012 00:32:47 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

None of this is unexpected. The original number, represented as a rational, is: x = 637101/100 637101/100 (unchanged by automatic factor cancellations) 100 is not a power of two, so the fraction CANNOT be exactly represented in binary floating point. The stored representation and its rational equivalent are: {bits, digitsToLeft} = RealDigits[N@x, 2] digitsToRight = Length@bits - digitsToLeft rational = FromDigits[bits, 2]/2^digitsToRight {{1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0}, 13} 40 3502499787838587/549755813888 The stored number is not equal to the original, of course: x == rational False But it's "close": N[rational] 6371.01 N[rational, 50] 6371.0100000000002182787284255027770996093750000000 If you're wondering how FromDigits works, consider: FromDigits[bits, z] // Expand % /. z -> 2 z + z^2 + z^4 + z^5 + z^6 + z^7 + z^11 + z^13 + z^18 + z^19 + z^20 + \ z^22 + z^24 + z^25 + z^26 + z^27 + z^31 + z^33 + z^40 + z^41 + z^45 + \ z^46 + z^47 + z^51 + z^52 7004999575677174 %/2^40 3502499787838587/549755813888 Bobby On Tue, 24 Apr 2012 04:33:56 -0500, Ralph Dratman <ralph.dratman at gmail.com> wrote: > One could argue that because those digits were not specified, they > could be anything. > > Just kidding! Still, they could be anything. > > > > On Mon, Apr 23, 2012 at 5:41 AM, Alexander Mayer <amayer at alum.mit.edu> > wrote: >> In[1]:= (* This notebook produced by Mathematica 8.0.4.0 *) >> (* Platform: OSX 10.6.8 on MacBook Pro *) >> >> In[1]:= b = 6371.01 (* We set the value of b to this real number. *) >> >> Out[1]= 6371.01 >> >> In[2]:= SetPrecision[a = b, 20] (* We test the actual value of b. *) >> >> Out[2]= 6371.0100000000002183 >> >> In[3]:= (* Mathematica has added a small constant! *) > -- DrMajorBob at yahoo.com