# How do calculators find the square-root of a #?

**URL:** <https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149>\
**Category:** Factual Questions\
**Created:** [January 12, 2000, 5:16pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149 "2000-01-12T17:16:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZRUDEDOG13](https://avatars.discourse-cdn.com/v4/letter/z/51bf81/32.png) [@ZRUDEDOG13](https://boards.straightdope.com/u/ZRUDEDOG13)\
**Post date:** [January 12, 2000, 5:16pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/1 "2000-01-12T17:16:00Z")

</div>

If there isn’t a formula for finding a  
square-root of a number, how do calculators  
find them so efficiently?

---

<div class="post-metadata">

**Author:** ![pluto](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@pluto](https://boards.straightdope.com/u/pluto)\
**Post date:** [January 12, 2000, 5:37pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/2 "2000-01-12T17:37:00Z")

</div>

There is a formula, which some of us are old enough to have been taught in elementary school.

I think, though, that calculators use an method of successive approximations using a technique known as the Newton-Raphson method. You make a guess and then make your next guess based on the results of the previou one. Newton-Raphson guarantees your guesses get better and better and it converges very quickly. You stop guessing when you have enough digits in your answer.

Your statement that calculators do things efficiently is a little over-confident. They do things pretty quickly, but they are not necessarily all that efficient.

* * *

That’ll do, pig. That’ll do.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/straightdope/original/2X/e/e489c3b7d8fce19c4b355dd4fc3f88cc39c34b87.png) [@system](https://boards.straightdope.com/u/system)\
**Post date:** [January 12, 2000, 5:54pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/3 "2000-01-12T17:54:00Z")

</div>

There are two ways for a calculator to find a square root.[list=1][li]Find the natural log, divide that by two, then raise _e_ to that result. The new number is the square root.[/li]  
[li]An algorithm:[/li]  
Let n be then number you want the square root of  
r[sub]1[/sub] be a first guess (half of n is a good start)

r[sub]1[/sub] \* n/r[sub]1[/sub] = n

If r[sub]1[/sub] is greater than sqrt(n), then n/r[sub]1[/sub] is less than, and vice versa. The average of them is closer to sqrt(n) than either of them were. So let the second guess r[sub]2[/sub] be (r[sub]1[/sub]+n/r[sub]1[/sub])/2

In general, then, repeat r[sub]j[/sub]=(r[sub]j-1[/sub]+n/r[sub]j-1[/sub])/2 until the new r[sub]j[/sub] isn’t significantly different than r[sub]j-1[/sub].[/list=1]

* * *

The Canadians. They walk among us. William Shatner. Michael J. Fox. Monty Hall. Mike Meyers. Alex Trebek. All of them Canadians. All of them here.

---

<div class="post-metadata">

**Author:** ![DrFidelius](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/drfidelius/32/3447_2.png) [@DrFidelius](https://boards.straightdope.com/u/DrFidelius)\
**Post date:** [January 12, 2000, 9:16pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/4 "2000-01-12T21:16:00Z")

</div>

Magic math pixies.

---

<div class="post-metadata">

**Author:** ![Earl\_Snake-Hips\_Tucker](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/earl_snake-hips_tucker/32/3269_2.png) [@Earl\_Snake-Hips\_Tucker](https://boards.straightdope.com/u/Earl_Snake-Hips_Tucker)\
**Post date:** [January 12, 2000, 9:18pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/5 "2000-01-12T21:18:00Z")

</div>

Mine has a button.

---

<div class="post-metadata">

**Author:** ![Jinx](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@Jinx](https://boards.straightdope.com/u/Jinx)\
**Post date:** [January 12, 2000, 9:22pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/6 "2000-01-12T21:22:00Z")

</div>

Easy! Just raise the number to the 1/2 power!  
There are some “cheap and dirty” methods to be done by hand…sounds kinda kinky! Newton didn’t run and get his HP or his slide-rule!

Maybe that’s why all these recent questions about Newton’s sexlife!

* * *

The scary thing is that 90% of the people think they’re above average! - unknown

---

<div class="post-metadata">

**Author:** ![Kat](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@Kat](https://boards.straightdope.com/u/Kat)\
**Post date:** [January 14, 2000, 3:30am UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/7 "2000-01-14T03:30:00Z")

</div>

> [@](#):
>
> Originally posted by DrFidelius:  
> **Magic math pixies.**

That’s what I thought.

---

<div class="post-metadata">

**Author:** ![CurtC](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@CurtC](https://boards.straightdope.com/u/CurtC)\
**Post date:** [January 14, 2000, 6:02am UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/8 "2000-01-14T06:02:00Z")

</div>

Jinx wrote:

> [@](#):
>
> The scary thing is that 90% of the people think they’re above average!

The scary thing is that some people believe this to be mathematically impossible!

---

<div class="post-metadata">

**Author:** ![douglips](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@douglips](https://boards.straightdope.com/u/douglips)\
**Post date:** [January 14, 2000, 6:52am UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/9 "2000-01-14T06:52:00Z")

</div>

The scary thing is, 90% of people think they are above the median!

---

<div class="post-metadata">

**Author:** ![Mc\_Ph\_st\_Y\_Cheesehead](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Mc\_Ph\_st\_Y\_Cheesehead](https://boards.straightdope.com/u/Mc_Ph_st_Y_Cheesehead)\
**Post date:** [January 14, 2000, 7:17am UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/10 "2000-01-14T07:17:00Z")

</div>

Actually, I hate to say this, but everybody is wrong so far. You have to keep in mind all a calculator is, is a small computer. As a Computer Systems Technology student, one of the dreadfully fun classes we got to take was Computational Mathematics… and you guessed it, one of the things we learned was square rooting.

Now, it’s 1 in the morning and I don’t have the energy to explain it, rather I’ll let y’all hang for a while. But keep this in mind: Because a calculator is simply a small computer, calculators must make calculations according to the “laws and rules” of binary.

In other words: Computers CAN NOT multiply or divide, they can only ADD and SUBTRACT. Ahhhhh, the beauties of binary.

I’ll be back tomorrow after sleeping and I’ll tell you guys how it’s done… hell, maybe I’ll even give you guys the algorithm. =)

* * *

Mc[Ph|st]Y Cheesehead

“Software is like sex, it’s better when it’s free.” -Linus Torvalds on the software industry.

---

<div class="post-metadata">

**Author:** ![RM\_Mentock](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@RM\_Mentock](https://boards.straightdope.com/u/RM_Mentock)\
**Post date:** [January 14, 2000, 3:25pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/11 "2000-01-14T15:25:00Z")

</div>

> [@](#):
>
> In other words: Computers CAN NOT multiply or divide, they can only ADD and SUBTRACT. Ahhhhh, the beauties of binary.

Four words: Math co-processors.

.

---

<div class="post-metadata">

**Author:** ![John\_W.Kennedy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/john_w.kennedy/32/1031_2.png) [@John\_W.Kennedy](https://boards.straightdope.com/u/John_W.Kennedy)\
**Post date:** [January 14, 2000, 7:44pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/12 "2000-01-14T19:44:00Z")

</div>

> [@](#):
>
> 1. An algorithm:
> 
> Let n be then number you want the square root of r1 be a first guess (half of n is a good start)
> 
> r1 \* n/r1 = n
> 
> If r1 is greater than sqrt(n), then n/r1 is less than, and vice versa. The average of them is closer to sqrt(n) than either of them were. So let the second guess r2 be (r1+n/r1)/2
> 
> In general, then, repeat rj=(rj-1+n/rj-1)/2 until the new rj isn’t significantly different than rj-1.

In general, yes, but since modern calculators work in floating point, the number is normally held as some fraction times a power of two. You can get a much better initial guess by dividing the power of two by two.

```auto

Sample: Square root of 10:

10 = .625 times 2^4

Initial guess: .625 times 2^(4/2) = 2.5.

1. 10 / 2.5 = 4.
   (2.5 + 4) / 2 = 3.25
2. 10 / 3.25 = 3.076923076923
   (3.25 + 3.076923076923) / 2 = 3.163461538462
3. 10 / 3.163461538462 = 3.161094224924
   (3.163461538462 + 3.161094224924) / 2 = 3.162277881693
4. 10 / 3.162277881693 = 3.162277438644
   (3.162277881693 + 3.162277438644) / 2 = 3.162277660168
5. 10 / 3.162277660168 = 3.162277660169

```

In just 5 steps, we get the answer.

* * *

John W. Kennedy  
“Compact is becoming contract; man only earns and pays.”  
– Charles Williams

---

<div class="post-metadata">

**Author:** ![gazpacho](https://avatars.discourse-cdn.com/v4/letter/g/6f9a4e/32.png) [@gazpacho](https://boards.straightdope.com/u/gazpacho)\
**Post date:** [January 14, 2000, 10:43pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/13 "2000-01-14T22:43:00Z")

</div>

Computers can definately multiply. The chip I am working now on has serveral multipliers of  
vaious sizes.

---

<div class="post-metadata">

**Author:** ![Cooper](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Cooper](https://boards.straightdope.com/u/Cooper)\
**Post date:** [January 14, 2000, 11:06pm UTC](https://boards.straightdope.com/t/how-do-calculators-find-the-square-root-of-a/6149/14 "2000-01-14T23:06:00Z")

</div>

> [@](#):
>
> In other words: Computers CAN NOT multiply or divide, they can only ADD and SUBTRACT. Ahhhhh, the beauties of binary.

Don’t mistake the trees for the forest.

Computers may break down all operations to an addition or a subtraction at the lowest level - but I don’t think its necessary to explain that to answer the question. For all practical purposes, computers do multiply and divide.
