2 /* @(#)z_sqrtf.c 1.0 98/08/13 */
3 /*****************************************************************
4 * The following routines are coded directly from the algorithms
5 * and coefficients given in "Software Manual for the Elementary
6 * Functions" by William J. Cody, Jr. and William Waite, Prentice
8 *****************************************************************/
9 /******************************************************************
13 * x - floating point value
19 * This routine performs floating point square root.
21 * The initial approximation is computed as
22 * y0 = 0.41731 + 0.59016 * f
23 * where f is a fraction such that x = f * 2^exp.
25 * Three Newton iterations in the form of Heron's formula
26 * are then performed to obtain the final value:
27 * y[i] = (y[i-1] + f / y[i-1]) / 2, i = 1, 2, 3.
29 *****************************************************************/
40 /* Check for special values. */
50 return (z_notanum_f
.f
);
55 return (z_infinity_f
.f
);
59 /* Initial checks are performed here. */
65 return (z_notanum_f
.f
);
68 /* Find the exponent and mantissa for the form x = f * 2^exp. */
72 /* Get the initial approximation. */
73 y
= 0.41731 + 0.59016 * f
;
76 /* Calculate the remaining iterations. */
77 for (i
= 0; i
< 2; ++i
)
80 /* Calculate the final value. */
92 #ifdef _DOUBLE_IS_32BITS
94 double sqrt (double x
)
96 return (double) sqrtf ((float) x
);
99 #endif /* _DOUBLE_IS_32BITS */