Archive for April 19th, 2009

19
Apr
09

[C++] Approximating Squares: Bakhshali Approximation

double BakhshaliApproximation(double value, int n)
{
	return (n+((value - n*n)/(2*n)))-(((value - n*n)/(2*n))*((value - n*n)/(2*n))/(2*(n+((value - n*n)/(2*n)))));
}

Usage:
Where Value = the square you wish to find and N = Closest perfect square to Value.

std::cout << BakhshaliApproximation(9.2345, 3) << "\n";

Would Output:
3.038832022859598

which is approx = Sqrt(9.2345)