double sqrt (double x) { double f, y; int exp, i, odd; /* Check for special values. */ switch (numtest (x)) { case NAN: errno = EDOM; return (x); case INF: if (ispos (x)) { errno = EDOM; return (z_notanum.d); } else { errno = ERANGE; return (z_infinity.d); } } /* Initial checks are performed here. */ if (x == 0.0) return (0.0); if (x < 0) { errno = EDOM; return (z_notanum.d); } /* Find the exponent and mantissa for the form x = f * 2^exp. */ f = frexp (x, &exp); odd = exp & 1; /* Get the initial approximation. */ y = 0.41731 + 0.59016 * f; f /= 2.0; /* Calculate the remaining iterations. */ for (i = 0; i < 3; ++i) y = y / 2.0 + f / y; /* Calculate the final value. */ if (odd) { y *= __SQRT_HALF; exp++; } exp >>= 1; y = ldexp (y, exp); return (y); }
double exp (double x) { int N; double g, z, R, P, Q; switch (numtest (x)) { case NAN: errno = EDOM; return (x); case INF: errno = ERANGE; if (ispos (x)) return (z_infinity.d); else return (0.0); case 0: return (1.0); } /* Check for out of bounds. */ if (x > BIGX || x < SMALLX) { errno = ERANGE; return (x); } /* Check for a value too small to calculate. */ if (-z_rooteps < x && x < z_rooteps) { return (1.0); } /* Calculate the exponent. */ if (x < 0.0) N = (int) (x * INV_LN2 - 0.5); else N = (int) (x * INV_LN2 + 0.5); /* Construct the mantissa. */ g = x - N * LN2; z = g * g; P = g * ((p[2] * z + p[1]) * z + p[0]); Q = ((q[3] * z + q[2]) * z + q[1]) * z + q[0]; R = 0.5 + P / (Q - P); /* Return the floating point value. */ N++; return (ldexp (R, N)); }
double fabs (double x) { switch (numtest (x)) { case NAN: errno = EDOM; return (x); case INF: errno = ERANGE; return (x); case 0: return (0.0); default: return (x < 0.0 ? -x : x); } }
double atan (double x) { switch (numtest (x)) { case NAN: errno = EDOM; return (x); case INF: /* this should check to see if neg NaN or pos NaN... */ return (__PI_OVER_TWO); case 0: return (0.0); default: return (atangent (x, 0, 0, 0)); } }
-0.23823859153670238830e+2 }; static const double a[] = { 0.0, 0.78539816339744830962 }; static const double b[] = { 1.57079632679489661923, 0.78539816339744830962 }; double _DEFUN (asine, (double, int), double x _AND int acosine) { int flag, i; int branch = 0; double g, res, R, P, Q, y; /* Check for special values. */ i = numtest (x); if (i == NAN || i == INF) { errno = EDOM; if (i == NAN) return (x); else return (z_infinity.d); } y = fabs (x); flag = acosine; if (y > 0.5) { i = 1 - flag;