How does the computer calculate Square roots ? I mean what is going on there! How does it process it!! Does it use some mathematical ways like Newton's method? What about Trigonometric Functions? And almost all those Mathematical Functions . In the case that every language has its own way, then please let's talk about c++.
In the Google search box, type the square root command – the sqrt symbol – and the number you want to know the square root of. For example, to find the square root of 75, type "sqrt 75" or "square root 75" and select "Enter." As soon as you finish typing, Google displays the square root result.
The square root algorithm is set up so that we take the square root of a number in the form of (X + R)2. The square root of this number is obviously (X + R). X represents the current approximation for the square root, and R represents the remainder of the number left over from the approximation.
Most modern non-embedded CPUs (x86 and the larger ARM cores, for example) have hardware instructions to compute square roots directly. The hardware implementation backing these instructions varies, but typically is a variant on the schoolbook digit-by-digit algorithm (though not always in base two; base four or sixteen can also be used). These are typically among the slowest basic arithmetic operations on a CPU; timings like 16-64 cycles are not uncommon, and these instructions are often not pipelined.
On CPUs that lack direct hardware square root instructions (Itanium, PPC, others), the typical approach is to generate an initial estimate (either with an instruction that produces the estimate, or with a lookup table) and then refine that estimate using an iterative method (Newton or Goldschmidt usually). You might track down some of Peter Markstein or Roger Golliver's writings on the subject if you're interested.
More complex mathematical functions (like trig operations) are typically computed by reducing the argument into some fundamental domain and then approximating it with a polynomial or rational function. You can look at the sources of any of several math libraries that are available online for more detail (fdlibm is a good starting point).
The x86 instruction set provides a number of instructions that support mathematical functions like exp, log, and sin, but these are not commonly used anymore, because good software library implementations give better performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With