1 /* ef_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 * ====================================================
19 static const float one
= 1.0, tiny
=1.0e-30;
21 static float one
= 1.0, tiny
=1.0e-30;
25 float __ieee754_sqrtf(float x
)
27 float __ieee754_sqrtf(x
)
32 __int32_t sign
= (__int32_t
)0x80000000;
34 __int32_t ix
,s
,q
,m
,t
,i
;
39 /* take care of Inf and NaN */
40 if(!FLT_UWORD_IS_FINITE(hx
))
41 return x
*x
+x
; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
43 /* take care of zero and -ves */
44 if(FLT_UWORD_IS_ZERO(hx
)) return x
;/* sqrt(+-0) = +-0 */
45 if(ix
<0) return (x
-x
)/(x
-x
); /* sqrt(-ve) = sNaN */
49 if(FLT_UWORD_IS_SUBNORMAL(hx
)) { /* subnormal x */
50 for(i
=0;(ix
&0x00800000L
)==0;i
++) ix
<<=1;
53 m
-= 127; /* unbias exponent */
54 ix
= (ix
&0x007fffffL
)|0x00800000L
;
55 if(m
&1) /* odd m, double x to make it even */
57 m
>>= 1; /* m = [m/2] */
59 /* generate sqrt(x) bit by bit */
61 q
= s
= 0; /* q = sqrt(x) */
62 r
= 0x01000000L
; /* r = moving bit from right to left */
75 /* use floating add to find out rounding direction */
77 z
= one
-tiny
; /* trigger inexact flag */
86 ix
= (q
>>1)+0x3f000000L
;