Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 9
    I'm always amazed by how simple this method is, and how fast it converges. It was known loooooong before Newton, BTW. Commented Jan 21, 2022 at 21:48
  • 6
    @EricDuminil Still, a Python implementation of Newton's method for sqrt will probably always be much slower than the builtin sqrt function and therefore not recommended for practical purposes. The answer would be improved if it would discuss when this implementation should be used (higher accuracy maybe even or faster for arbitrary roots or showcasing what math.sqrt likely does)? Commented Jan 22, 2022 at 15:46
  • 5
    @Trilarion math.sqrt probably directly calls a processor's square root instruction. The only good reason I can think of for using something else is when you have unique requirements, e.g. looking for an integer square root. Commented Jan 22, 2022 at 19:23
  • You can swap types in this version too, and using fractions or fixed point numbers can fix the problem of this being a slower math.sqrt too. Commented Jan 25, 2022 at 14:35
  • I don't think it is a good idea to implement such a critical function in Python itself. I'd rather make this a C function and call that from Python. Commented Jan 27, 2022 at 7:18

lang-py