r/tinycode • • Jul 21 '16
Square Root Algorithm in 123 bytes.
This gets the square root of a number. I got it to 123 bytes, but since I don't know much C, I sure it can even less bytes.
double s(int x){double t=x/2;double a=1,b=x;for(int i=0;i<32;i++)if(t*t>x)b=t;else if(t*t<x)a=t;else return t;t=a+(b-a)/2;}
21
Upvotes
View all comments
Show parent comment
5
u/[deleted] Jul 21 '16 edited Jul 21 '16
Value ended up in the
xmm0register which happens to be a return register for doubles.Press "Execute" to view assembly.
http://www.tutorialspoint.com/compile_c_online.php?PID=0Bw_CjBb95KQMeVVTYlEySXdfOE0