Last active
March 30, 2017 13:09
-
-
Save adler3d/297dddd760c959d11ef348d1182d9528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
auto sqr=[](int x){return x*x;}; | |
auto sqrt=[sqr](int x){ | |
auto center=[](int a,int b){return (a+b)>>1;}; | |
int low=0<<(sizeof(x)*8/2); | |
int top=1<<(sizeof(x)*8/2); | |
cout<<"top = "<<top<<endl; | |
for(int i=0;i<32;i++){ | |
cout<<"low = "<<low<<" top = "<<top<<endl; | |
int c=center(low,top);cout<<c<<endl; | |
(c*c<=x?low:top)=c; | |
if(sqr(c+0)<=x)if(sqr(c+1)>x)return c; | |
} | |
return -1; | |
}; | |
cout<<"result = "<<sqrt(sqr(31000))<<endl;; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment