From: James W Sager Iii Newsgroups: comp.os.msdos.djgpp Subject: So I coded up my own square root function Date: Sat, 17 Mar 2001 01:28:39 -0500 Organization: Carnegie Mellon, Pittsburgh, PA Lines: 81 Message-ID: NNTP-Posting-Host: po8.andrew.cmu.edu X-Trace: bb3.andrew.cmu.edu 984810769 1667 128.2.10.108 (17 Mar 2001 06:32:49 GMT) X-Complaints-To: advisor AT andrew DOT cmu DOT edu NNTP-Posting-Date: 17 Mar 2001 06:32:49 GMT X-Added: With Flames (outnews v2.6) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Stupid djgpp isn't doing sqrt right so I made my own. Its processing time is like O log(n) or so. Returns an integer square root value within 1. #include int ghettosqr(int square); void main(void) { int a; cout< square ) if(((a-1)*(a-1)) < square ) return a; if((a*a) < square ) if(((a+1)*(a+1)) > square ) return a; //If incrementing and the guess is over estimated reverse the binary search if(addsub == 1) if(a*a > square) { //if(add < 2) //return a; add=add/4; addsub=-1; divisor = divisor * 1.1; } //If decrementing and the guess is under estimated reverse the binary search if(addsub == -1) if(a*a