# Fixed Point square root algorithm

**URL:** <https://boards.straightdope.com/t/fixed-point-square-root-algorithm/318693>\
**Category:** Factual Questions\
**Created:** [August 26, 2005, 4:18am UTC](https://boards.straightdope.com/t/fixed-point-square-root-algorithm/318693 "2005-08-26T04:18:42Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![Hypnagogic\_Jerk](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hypnagogic_jerk/32/4252_2.png) [@Hypnagogic\_Jerk](https://boards.straightdope.com/u/Hypnagogic_Jerk)\
**Post date:** [August 29, 2005, 3:50am UTC](https://boards.straightdope.com/t/fixed-point-square-root-algorithm/318693/21 "2005-08-29T03:50:07Z")

</div>

> [@Master Control](#):
>
> Here’s my code for testing the algorithm. Works every time.
> 
> [Code Deleted]

Well, yeah. You take the smallest positive number recognized by your machine, do a first iteration of Newton’s method (bringing you over the exact square root), and _then_ check to see if the difference between the square of your numerical value and the number whose root you want to extract is smaller than machine precision. If not, you iterate again. So yes, it will work. What I’m saying is that taking the smallest positive number on your machine may not be an optimal choice (but as you say, choosing an optimal choice would require more overhead), and that maybe you could use a tolerance that’s not as good as machine precision. But in this case, it’s not that necessary: the algorithm is fast enough anyway. And if your machine precision is 0.01, you probably can’t go much coarser than that.

All right.

[Previous page](https://boards.straightdope.com/t/fixed-point-square-root-algorithm/318693.md?page=1)
