Two simple algorithms for square roots

zhaozj2021-02-11  193

Square root algorithm

1.b = a / 2; while (ABS (B * B-a)> e) // E is a small number, indicating the accuracy B = (B A / B) / 2 of the algorithm;

2. Conditions: n (n 2 * q * r) <= yn enrollment, q = n; r is the last result of the last time; N is the maximum value of the satisfaction condition to meet; y is calculated The remainder (Note: When the renewal is supplemented, if it is 10, it should be supplemented 100, that is, 10 * 10; binary, 10, ie 2 * 2)

Example 1:10 Square root (10) SQRT (10) = 3.1622776601683793319988935444327

3. 1 6 2) 10 9 <= n (n 2 * q * r) = 3 * (3 2 * 10 * 0) = 9 <10 3 1 00 61 <= N (N 2 * Q * R) = 1 * (1 2 * 10 * 3) = 61 <100 1 39 00 37 56 <= n (n 2 * q * r) = 6 * (6 2 * 10 * 31) = 3756 <3900 6 1 44 00 1 26 44 <= n (n 2 * q * r) = 2 * (2 2 * 10 * 316) = 12644 <14400 2 17 56 .... ... .

Example 2:10 Square root (2) N (n 2 * q * r) due to: n = 0 or 1 q = 2 r = unknown So: N (n 2 * q * r) <=> R << 2 1

(10) D = (1010) BSQRT (10) = (3.16277660168379331988935444327) D = (0011.0010 1001 1000) B 1 1. 0 0 1 0) 10 10 1 <= r << 2 1 = 0 << 2 1 = 0 1 = 1 <10 1 1 10 1 01 <= r << 2 1 = 1 << 2 1 = 100 1 = 101 <110 on 1 00 0 <= r << 2 1 << 2 1 = 11 = 1100 1 = 1101> 100 a 0 1 00 00 0 <= R << 2 1 = 110 << 2 1 = 11000 1 = 11001> 10000 on 01 million 11 00 01 <= r << 2 1 = 1100 << 2 1 = 110000 1 = 110001 <1000000 on 1 11 11 ...... ...

转载请注明原文地址:https://www.9cbs.com/read-5685.html

New Post(0)