A general programming discussion community.
Rules:
- Be civil.
- Please start discussions that spark conversation
Other communities
Systems
Functional Programming
Also related
- 0 users online
- 5 users / day
- 14 users / week
- 44 users / month
- 138 users / 6 months
- 1 subscriber
- 336 Posts
- 544 Comments
- Modlog
square_root
takes auint64_t
argument then it should return auint32_t
x = (x + (s / x)) / 2;
This update of the test value uses integer divisions which means it is not guaranteed to converge (due to the truncation moving your approximation further away than the previous iteration). You should also check that x > 0 to avoid accidental division by zero.seed
is trying to calculate pow(10, log_100(x)) in some way, but it has bugs, for examplea < 10
is true for radicand values of 100-999, 10000-99999, 1000000-9999999 etc. which probably isn’t what you want. An easier way to estimate a starting value for the first iteration would be to take a number that has half as many bits as the input, since we know that if a number X uses K bits then its square root will use K/2 bits. You can use a method to calculate the position of the most significant set bit in the input and then use 2^(k/2) as the seed.-Wall -Werror
(with gcc) to enforce those checks and make them compile errors that you must fix.deleted by creator