Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9780 > unrolled thread
| Started by | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| First post | 2012-04-25 04:34 +0000 |
| Last post | 2012-04-25 04:34 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version) DrMajorBob <btreat1@austin.rr.com> - 2012-04-25 04:34 +0000
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2012-04-25 04:34 +0000 |
| Subject | Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version) |
| Message-ID | <jn7usf$6bo$1@smc.vnet.net> |
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@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@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@yahoo.com
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web