title: Floating point numbers of Python "float" and PostgreSQL "double precision"
body: <p>Are Python's "float" type and PostgreSQL's "double precision" type based on the same C implementation? That may not be the real underlying problem here, but anyway, here's what I get when I try to manipulate small numbers in both environments:</p>
  
  <p>On Python (2.7.2 GCC 4.2.1, if that's relevant):</p>
  
  <pre><code>&gt;&gt;&gt; float('1e-310')
  1e-310
  </code></pre>
  
  <p>On PostgreSQL (9.1.1):</p>
  
  <pre><code>postgres# select 1e-310::double precision;
  ERROR:  "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" is out of range for type double precision
  </code></pre>
  
  <p>What I understand is that Python float type "handles" 1e-310 while PostgreSQL double precision type does not.
  Both <a href="http://docs.python.org/tutorial/floatingpoint.html" rel="noreferrer">Python</a> and <a href="http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-FLOAT" rel="noreferrer">PostgreSQL</a> docs on, respectively, "float" and "double precision" types, refer to the IEEE 754 standard, which is supposed to be implemented on "most platforms" (I'm on OS X Lion 10.7.3).</p>
  
  <p>Could anyone explain what's happening here? And give me a solution, I'd like for instance to "reduce" Python precision so I can insert floats in my database through a Django FloatField. (The full use case is that I'm reading figures from a file and then inserting them).</p>
  
  <p>Some (maybe interesting) additional information, in Python:</p>
  
  <pre><code>&gt;&gt;&gt; sys.float_info
  sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
  &gt;&gt;&gt; 1e-320.__sizeof__()
  24
  </code></pre>
  
  <p>I really don't get the second one.</p>