1 /* e_sqrtf.c -- float version of e_sqrt.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
17 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/e_sqrtf.c,v 1.7 2002/05/28 18:15:04 alfred Exp $";
21 #include "math_private.h"
23 static const float one
= 1.0, tiny
=1.0e-30;
26 __ieee754_sqrtf(float x
)
29 int32_t sign
= (int)0x80000000;
35 /* take care of Inf and NaN */
36 if((ix
&0x7f800000)==0x7f800000) {
37 return x
*x
+x
; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
40 /* take care of zero */
42 if((ix
&(~sign
))==0) return x
;/* sqrt(+-0) = +-0 */
44 return (x
-x
)/(x
-x
); /* sqrt(-ve) = sNaN */
48 if(m
==0) { /* subnormal x */
49 for(i
=0;(ix
&0x00800000)==0;i
++) ix
<<=1;
52 m
-= 127; /* unbias exponent */
53 ix
= (ix
&0x007fffff)|0x00800000;
54 if(m
&1) /* odd m, double x to make it even */
56 m
>>= 1; /* m = [m/2] */
58 /* generate sqrt(x) bit by bit */
60 q
= s
= 0; /* q = sqrt(x) */
61 r
= 0x01000000; /* r = moving bit from right to left */
74 /* use floating add to find out rounding direction */
76 z
= one
-tiny
; /* trigger inexact flag */
85 ix
= (q
>>1)+0x3f000000;