<Span style = "font-size: 14px;"> </span>
Today, I borrowed a high-performance programmer training book from the library, which is humorous. (In fact, I borrowed it when I saw that the author was the founder of stack overflow ). One example on dozens of pages is about square root. The code is very simple, but ''' is not understood for the first time ····Only then can we know that the principle is based on the Newton-laferson method, I .e. the Newton Iteration Method. For details, refer to Baidu.
<Span style = "font-size: 14px;"> private double squarebootappr (int n) {double r = n/2; while (ABS (R-N/R)> t) // T = 0.0000001 {r = 0.5 * (R + N/R);} return r ;}</span>
Another method is shift. The square root is used to calculate the square. If the square of the result is less than N. Less than N, the highest position is 1, and the opposite is 0 .(There is no first method with High Precision)
<Span style = "font-size: 14px;"> private double squarebootappr (int n) {int r = 0; For (INT I = 15; I> 0; I ++) {If (R + (1 <I) * (R + (1 <r) <n) {R + = 1 <I ;}} return r ;}</span>
Evaluate the square root of integer N (without library function)