/* Sneaky square root (C) 1997 by D. Corbit */ static long double const val28 = 28.0e0L; static long double const val70 = 70.0e0L; static long double const val6 = 6.0e0L; static long double const valOneEighth = 0.125e0L; static long double const valOneHalf = 0.5e0L; long double SqrtAB07(long double x, long double c) { long double x2 = x * x; long double x4 = x2 * x2; long double x8 = x4 * x4; long double c2 = c * c; long double c4 = c2 * c2; long double ans0 = (val28 * (x2 * c * (x4 + c2)) + (val70 * c2 + x4) * x4 + c2 * c2) / (x * (x2 + c) * (x4 + val6 * x2 * c + c2)) * valOneEighth; long double ans1 = c / ans0; return (ans0 + ans1) * valOneHalf; } #ifdef TEST #include int main(void) { long double c = 2.0e0L; long double guess = 1.2e0L; guess = SqrtAB07(guess, c); printf("Square root of %Lg is estimated at\n %.18Le after 1 iteration.\n", c, guess); return 0; } #endif