Hi I was quite sure about this matter until I came across a comment in a old blog that suggested other wise I searched the internet but I didn't find anywhere mentioning anything about logarithmic runtime(and no source said anything about constant time) but I'm just checking
Thanks
I guess you can think of binary searching the value of $$$\sqrt{n}$$$, you know that it must range from 1 to $$$n$$$, so it takes $$$log(n)$$$ runtime. Please correct me if I am wrong.
Thank you Yes I am aware of the log n method but does the built in sqrt() use this algorithm?
.
Please do not post links to offensive sites such as GeeksForGeeks, many of those who visit CodeForces are underage...
"offensive" as in?
he is joking, because gfg have many wrong, inaccurate articles.
They probably use Newton's Method.
Thanks
sqrt is directly compiled to
sqrtsd
instruction on x86 starting with-O1
. We can only speculate how it works in hardware. It certainly does not use Newton-Raphson method because IEEE-754 requiressqrt
to have perfect precision (<= 0.5 ulp). It probably uses a method similar to long division (which is also a speculation, but it makes sense because div and sqrt are implemented in the same hardware unit).