#include double cbrt(double c) { int n; int exponent; int sign; double x; double x2; double x6; double c2; double x3c; double x3c16; double tenx6; double temp; double ans0; double ans1; sign = (c < 0.0 ? 1 : 0); if (sign) c = -c; x = frexp(c, &exponent); x = 0.59130052 + 0.41533799 * x; x2 = x * x; x6 = x2 * x2 * x2; c2 = c * c; x3c = x2 * x * c; x3c16 = x3c * 16.; tenx6 = 10. * x6; temp = x3c16 + tenx6 + c2; ans0 = x * (4.0 * (x6 + c2) + 19.0 * x3c) / (temp); ans1 = 1. / x2 * c * (temp) / (x3c16 + 10. * c2 + x6); x = (ans0 + ans1) * 0.5; n = (exponent % 3); exponent -= n; if (n < 0) { n += 3; exponent -= 3; } if (n == 1) x *= 1.25992104989487316476721; /* cube root of 2 */ else if (n == 2) x *= 1.5874010519681994747517; /* cube root of 4 */ x = ldexp(x, exponent / 3); return (sign ? -x : x); }