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 7961863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:10:11+00:00 2026-06-04T05:10:11+00:00

I was playing around with a simple recursive formula and noticed that the code

  • 0

I was playing around with a simple recursive formula and noticed that the code

p = 2.0

while p < 3.0:
    print p
    p = (6+p)**(0.5)

will print

*snip*
...
2.99999999952
2.99999999992
2.99999999999
3.0
3.0
3.0
3.0
3.0
3.0

Of course there will be some kind of approximation between 2.99999999999 and 3.0 (and before that) but what is actually happening here? For me it seems odd that the floating point 3.0 will be interpreted as something not quite 3.0 but still close enough to be called 3.0, several times in a row.

Am I doing something wrong, code-wise, here or is my interpretation correct? I if so, why is this happening?

  • 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-06-04T05:10:13+00:00Added an answer on June 4, 2026 at 5:10 am

    If you change the print statement like so:

    print '%.20f' % p
    

    all will become clear:

    2.00000000000000000000
    2.82842712474619029095
    2.97126692250060076006
    2.99520732546189538681
    2.99920111454065274614
    2.99986684946859805123
    2.99997780816268644344
    2.99999630135816763854
    2.99999938355963147174
    2.99999989725993687628
    2.99999998287665592400
    2.99999999714610909862
    2.99999999952435159045
    2.99999999992072519106
    2.99999999998678745783
    2.99999999999779776161
    2.99999999999963273822
    2.99999999999993871569
    2.99999999999998978595
    2.99999999999999822364
    2.99999999999999955591
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just playing around with a simple program that opens the camera. That's literally
I've been playing around with Simple.Data and have run across something that I can't
I'm playing around with a simple webserver written in F#. As I have noticed,
I have a simple hello, world servlet application that I am just playing around
I am just playing around with code blocks and writing a very simple program,
I'm playing around with MVC3 and trying to create a simple contact form that
I've been playing around with the HTML5 Canvas and I've noticed something that I
I'm playing around with using ASP.NET MVC3 and have a very simple site that
I've been playing around with Expression Trees. I have the following simple method that
I'm playing around with a simple test app that just loops through 10 images

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.