Smallest And Largest Floating Point Values In Python

In my production code, I have a function that calculates a/(a+b). That function threw a ZeroDivisionError at me this afternoon, so I decided to change the equation to a/(a+b+sys.minfloat), because I felt that was more elegant than writing a conditional function to check if (a + b) == 0.

Turns out there is no 'minfloat' in the sys module, so I decided to write a function to calculate the smallest float myself.
>>> def minfloat(guess):
while(guess * 0.5 != 0):
guess = guess * 0.5
return guess

>>> minfloat(+1.0) # minimum positive value of a float

>>> minfloat(-1.0) # minimum negative value of a float

But I couldn't stop there. Now I had to write a function to calculate the largest possible floating point value in Python, just for kicks:
>>> def maxfloat(guess = 1.0):
while(guess * 2 != guess):
guess = guess * 2
return guess

>>> maxfloat(+1.0) # maximum positive value of a float

>>> maxfloat(-1.0) # maximum negative value of a float

This is interesting. Let's find out more about this "inf" value:
>>> inf

Traceback (most recent call last):
File "", line 1, in
NameError: name 'inf' is not defined
>>> float("inf")

>>> inf = maxfloat()

>>> inf + inf

>>> inf - inf

>>> 1 / inf

>>> 1/(-inf)

Finally, check the relationship between minfloat and maxfloat:
>>> 1 / minfloat(1.0)
>>> 1 / minfloat(-1.0)

284 comments :: Smallest And Largest Floating Point Values In Python

«Oldest   ‹Older   201 – 284 of 284   Newer›   Newest»
  1. thanks… I’ve been bookmarking them for a while now and just decided to create a post to provide them to others…

    fridge repair mississauga

  2. More impressive Blog
    garage door repair strathmore

  3. OK, Got it clear

    Best Moment

    <a href="> Best Moment</a>

  4. <a href="> MarianneFeder </a>

  5. this information is very useful.
    เว็บพนัน UFABET

  6. I really love your weblog, Its great to find not absolutely everyone is just posting a ton of rubbish these days!

    emergency garage door repair ottawa

  7. I am not much into reading, but somehow I got to read lots of articles on your blog. Its amazing how interesting it is for me to visit you very often.

    GDR Tech Los Angeles

  8. אני לא מסכים עם כל מה שכתוב, אבל מאמר מעניין מאוד

    אינטרקום אלחוטי

  9. Are you looking for Bangalore Escorts or some fun with our Female Escorts Girls, if yes then you have at right place.
    South Bangalore Escorts
    Marathahalli Escorts
    Electronic City Escorts
    Hebbal Escorts
    Mg road Escorts
    Ulsoor Escorts
    Ub city Escorts
    Nandi hills Escorts
    Malleswaram Escorts

  10. Thanks for such a great post and the review, I am totally impressed! Keep stuff like this lice comb

  11. Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming..We buy houses Oakland

  12. Sir please I need your help

  13. Visit

  14. nice one

  15. We have calls available in the best of categories, according to our need, we are waiting for you, erotic and beautiful Hyderabad Escorts Service, you can come on our website and contact us 24x7 hours anytime Hyderabad Escort Service.

  16. We have calls available in the best of categories, according to our need, we are waiting for you, erotic and beautiful Chennai Escorts Service, you can come on our website and contact us 24x7 hours anytime Chennai Escort Service.


  18. My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends.

    AWS Course Syllabus

  19. How can I take my blog to the next stage

    the reality

  20. How can I take my blthereality
    next level

  21. Hurry Up to Book Now a Masterpiece Sizzling Escorts Hyderabad, and enjoy your night.
    We also provide our services in Mumbai: Escort in Mumbai

  22. How to report cyber crime to FBI

  23. I found the information you provided to be very helpful. I like your blog very much. It was a very useful experience for me. If you are planning an outdoor trip, then I suggest you check out the Best 4 Person Tent. Here are the best tents for four people that you can buy.

  24. Thank you for sharing this wonderful post. Thank you for the informative information. I really appreciate your effort toward the reader. I suggest reading the blog post on Camera and Microphone Hacking and protect yourself from hacking. There are several apps available on your phone or computer that can access your camera, microphone, and other features, including location information. Below are the steps you can follow to check which apps have asked for permission and revoke previously granted permissions.

  25. Hello viewer’s
    I don’t have much to say there are so may scammers going on online so we cant detect the real herbal medicine doctors. Thank GOD for leading me, please don’t ignore this post is real Dr Emmanuel, is a real herbal Doctor, he cured me from Herpes virus, i am living so happy and free , i was fully recovered within 4 weeks of usage of dr Emmanuel herbal medicine ,please viewers out there that have any deadly disease don't fail to contact him via his email; or WhatsApp/Call: +2348140073965 thanks once again to dr Emmanuel GOD bless you abundantly

  26. Do you need a sugar mummy or sugar daddy if yes call us on 09037906223

  27. Nice article I love it very informative. you can view Best 10 Moviesrulz Alternatives & Similar Websites thanks

    We offer certified and verifiable financial bank instruments via Swift Transmission from a genuine provider capable
    of taking up time bound transactions.
    LEASING FEE = 4%+2%
    PRICE = 32%+2%
    Our BG/SBLC Financing can help you get your project funded,
    loan financing by providing you with yearly.
    RWA ready to close leasing with any interested client in few banking days
    I will be glad to share with you our working procedures.
    Name : Thomas Wolfgang
    Email :
    Skype :

  29. Wow

  30. This comment has been removed by the author.
  31. Thank you for this informative article. I learned so much from it. Our free email signature maker will help you build a brand identity with a personalized email signature. Create your own email signature online with our free tool. Easily create a signature for your email using our email signature generator

  32. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    Selenium Course Training in Chennai
    RPA Course Training in Chennai

  33. The maximum value any floating-point number can be is approx 1.8 x 10308. Any number greater than this will be indicated by the string inf in Python.

    Winchester VA Basement Waterproofing

  34. That's very knowledgeable for me. Keep posting! See more at Newport Beach Tree Service

  35. Python supports 3 types of numbers: integers, float and complex number. If you want to know what type a value has you can use type() function. Thanks by the way! You can also visit our Tree Service Charlottesville

  36. Thank you for sharing this wonderful blog post, Keep posting for more! Visit us at

  37. This is nice tips for programming. Check out more info here.

  38. Python float values are represented as 64-bit double-precision values. View more about Spokane Kitchen Remodel

  39. A floating point number, is a positive or negative whole number with a decimal point. Get more info about
    AC Repair Spokane.

  40. thanks to you i learn a lot from this information. poker online

  41. Great content and comments.. if you are interested in food safety practices, you can check this page out:

  42. Hello Guys Enough already
    Yesterday night was loaded!!!!!

    *If you haven't watched the replay of the session we had yesterday, then you're are missing a whole lot of stuff*

    Here is the replay link to the class we had yesterday, rush niw to YouTube and watch it��

    *I'll be pulling down the link soon*

    Almost 2400 people have now streamed this‼️‼️

  43. Amazing blog. Thanks for sharing. basement-repair-wichita-ks

  44. Interesting and helpful blog. colorado springs concrete contractors

  45. Thanks for sharing such a nice blog. Looking for more.

  46. As a human being, if your inform u will surely be transform.....what make man poor is not spiritual battle or village people ....what makes man poor is simply because ,(people pass over opportunity repeatedly) {POOR}, with a wrong though of things they should check and try to confirm it authenticity before drawing conclusions...����� Check out that link and see the favour it will return to u and thank me letter. Good luck!

  47. Your blogs are really good and informative, keep sharing such good content.
    10 Marla Plots for Sale in Lahore

  48. Python uses 64-bit double-precision numbers to represent float values. Any floating-point number can have a maximum value of approximately 1.8 x 10308.

    Learn more also about Tree Pruning Spokane

  49. Thank you for this kind of information. Check this out Interior Window Cleaning

  50. Awesome post! Thanks for this.

  51. This site is interesting and indeed, very helpful. Thanks for sharing this!

  52. Your sharing in the article is very meaningful, the content is very rich and contains good things. Kitchener Appliance Services

  53. Fantastic! I think You put a lot of effort to create this article. I appreciate your work. check site

  54. It's an amazing and helpful source of information. I'm glad you shared this useful info with us. Sherwood Park Personal Trainer

  55. This is interesting post! Thanks for the share. my website

  56. Thanks for sharing this information. So great!

  57. Thank you! You've mentioned all your reader needs to know. Wall Trims Services

  58. Fantastic! I really appreciate the whole statement. Thanks for this!

  59. This comment has been removed by the author.
  60. Thanks for sharing this article ! it's really useful
    Tree Service In Richmond VA

  61. Cryptocurrency Scam/Fraud Tracing & Recovery
    I never thought I will get scammed of all my assets on this exchange which I was warned by friends not to invest online or apply for exchange from unknown online investors, they stole all my life saving ranging to a total sum of $68k [sixty eight thousand dollars] worth of bitcoin, i started regretting my life untill i came acrose some article online about jamesmckaywizard a genuine hacker who is into any kind of hacking and helping people recover their lost funds via online scam, I still didn't believe bitcoin can ever be recovered, but had to once again trust my guts and instinct. To my greatest surprise Mr. James was able to carry out the job neatly without any traces or complications all thanks to him and his team for offering me a top notch services. To that one person or persons out there who really need a true and efficient hacker l would advice you to contact: Email: / What's App:+91 98632 93475

  62. Interesting blog! I totally enjoy reading this blog Follow us

  63. I like to read it. Great effort by the author, really appreciative work. visit us

  64. Fantastic! I really appreciate the whole statement. Thanks for this! Richmond Protek Drywall

  65. This comment has been removed by the author.
  66. I gained a valuable understanding of the limitations and complexities involved in using floating-point numbers for calculations. The author's explanation of the precision issues, rounding errors, and the potential for unexpected results provided a compelling argument for the need to carefully consider the use of floating-point numbers in programming. This article serves as a reminder for programmers to be mindful of these intricacies and opt for alternative solutions when necessary.
    professional career counselor

  67. Nice post! Thanks for taking the time in sharing this great article in here.

    Mesa Plastic Surgery

  68. Thank you for the content. check our service

  69. Amazing, this blog should be up and running please

  70. "Thank you for sharing this.

    Plastic Surgery San Diego


  71. Very interesting article, and very educative as well... Thanks for this

  72. very informative content, thank you for sharing
    Plastic Surgery

  73. Additionally, Python has a special value called "inf" (infinity) which represents a value that exceeds the maximum finite representable floating-point value.

    See Concrete Sidewalk Summerville.

  74. Nice information. Thanks for sharing content and such nice information for me. I hope you will share some more content about. Please keep sharing!

    Find out more about the Synthetic Turf Durham NC

«Oldest ‹Older   201 – 284 of 284   Newer› Newest»

Post a Comment