KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Mathematica as in other systems of computer math the numbers are internally stored in binary form. However when exporting them with such functions as Put and PutAppend they are converted into approximate decimals. When you import them back with such functions as Get they are restored from this approximate decimal representation to binary form. The question is whether the recovered number is always identical to the original binary number and, if not always, in which cases it is not and how large can be the difference? I am particularly interested in the Put - Get cycle (on the same computer system). The following two simple experiments show that probably the Put - Get cycle in Mathematica always restores original numbers exactly even for arbitrary precision numbers: In[1]:= list=RandomReal[{-10^6,10^6},10000]; Put[list,"test.txt"]; list2=Get["test.txt"]; Order[list,list2]===0 Order[Total@Abs[list-list2],0.]===0 Out[4]= True Out[5]= True In[6]:= list=SetPrecision[RandomReal[{-10^6,10^6},10000],50]; Put[list,"test.txt"]; list2=Get["test.txt"]; Order[list,list2]===0 Total@Abs[list-list2]//InputForm Out[9]= True Out[10]//InputForm= 0``39.999515496936205 But maybe I am missing something? UPDATE With more correct test code I have found that in reality these tests show only that restored numbers have identical binary RealDigits but their Precision s may differ even in Equal sense. Here are more correct tests: test := (Put[list, "test.txt"]; list2 = Get["test.txt"]; {Order[list, list2] === 0, Order[Total@Abs[list - list2], 0.] === 0, Total[Order @@@ RealDigits[Transpose[{list, list2}], 2]], Total[Order @@@ Map[Precision, Transpose[{list, list2}], {-1}]], Total[1 - Boole[Equal @@@ Map[Precision, Transpose[{list, lis
Tags (comma-separated)
Save Edits
Cancel