title: Python float types vs Decimal
body: <p>I am an intern at TCD, Physics.</p>
  
  <p>I wrote a code to perform some data analysis on random particle packings. The code is written in Python.</p>
  
  <p>The code reads in columns of data from a .txt file, provided by my supervisor.</p>
  
  <p>Here is an example of the data:</p>
  
  <pre><code>0.52425196504624715921  0.89754790324432953685  0.44222783508101531913
  </code></pre>
  
  <p>I wrote the following code to read in the data:</p>
  
  <pre><code>from decimal import Decimal
  from numpy import *
  
  c1,c2,r = loadtxt("second.txt", usecols=(0,1,2), unpack=True, dtype = dtype(Decimal))
  </code></pre>
  
  <p>As you can see I used the Decimal dtype to read in all the decimal places of the number, and to be sure the calculations were reliable.</p>
  
  <p>Now, in order to speed up my code, I was wondering if there was a numpy dtype to make things faster, still using all decimal places, though. I did try:</p>
  
  <pre><code>c1,c2,r = loadtxt("second.txt", usecols=(1,2,4), unpack=True, dtype = float128)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>c1,c2,r = loadtxt("second.txt", usecols=(1,2,4), unpack=True, dtype = longdouble)
  </code></pre>
  
  <p>However here is the output compared:</p>
  
  <pre><code>Decimal :    0.98924652608783791852
  float128 :   0.98924653
  longdouble : 0.98924653
  float32 :    0.98924655
  </code></pre>
  
  <p>I am using a desktop, 64bit, 4GB RAM.</p>
  
  <p>Well, then I tried writing a code in C++ that basically multiplies every element of the columns of data by enough powers of 10 such that a new .txt file was produced with the following columns:</p>
  
  <pre><code>52425196504624715921    89754790324432953685    44222783508101531913
  </code></pre>
  
  <p>But when back to my Python code (I have to do this in Python):</p>
  
  <pre><code>  c1,c2,r = loadtxt("second.txt", usecols=(1,2,4), unpack=True, dtype = int)
  </code></pre>
  
  <p>I get the following error message: </p>
  
  <pre><code> OverflowError: Python int too large to convert to C long
  </code></pre>
  
  <p>Please pardon my limited knowledge of the language.</p>
  
  <p>Any solution is extremely welcome: I really need to speed up the code, either by reading directly the data or performing the required conversion to integers.</p>