Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:45:57+00:00 2026-05-31T02:45:57+00:00

Are Python’s float type and PostgreSQL’s double precision type based on the same C

  • 0

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:

On Python (2.7.2 GCC 4.2.1, if that’s relevant):

>>> float('1e-310')
1e-310

On PostgreSQL (9.1.1):

postgres# select 1e-310::double precision;
ERROR:  "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" is out of range for type double precision

What I understand is that Python float type “handles” 1e-310 while PostgreSQL double precision type does not.
Both Python and PostgreSQL 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).

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).

Some (maybe interesting) additional information, in Python:

>>> 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)
>>> 1e-320.__sizeof__()
24

I really don’t get the second one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:45:58+00:00Added an answer on May 31, 2026 at 2:45 am

    The value float(‘1e-310’) is a denormal number which is outside the usual range of exponents for 53-bit floats (+308 to -308) so it is stored with less precision in order to achieve gradual underflow.

    It seems the PostgreSQL has some unresolved issues with denormals: http://archives.postgresql.org/pgsql-hackers/2011-06/msg00885.php

    For values near zero, consider rounding them prior to storage in the DB:

    >>> round(float('1e-302'), 308)
    1e-302
    >>> round(float('1e-310'), 308)
    0.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python is so dynamic that it's not always clear what's going on in a
Python Decimal doesn't support being constructed from float; it expects that you have to
Python does not print traceback messages from exceptions raised in daemon threads. For example,
python 2.6 reports that the md5 module is obsolete and hashlib should be used.
Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
python newbie here. I'm writing the code to control an experiment that has multiple
Python has the idea of metaclasses that, if I understand correctly, allow you to
Python's convention is that variables are created by first assignment, and trying to read
Python's access to environment variables does not accurately reflect the operating system's view of
Python's arbitrary precision decimals are lovely, but I can't seem to find a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.