1 /* ef_hypot.c -- float version of e_hypot.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 float hypotf(float x
, float y
)
25 float a
=x
,b
=y
,t1
,t2
,y1
,y2
,w
;
32 if(hb
> ha
) {a
=y
;b
=x
;j
=ha
; ha
=hb
;hb
=j
;} else {a
=x
;b
=y
;}
33 SET_FLOAT_WORD(a
,ha
); /* a <- |a| */
34 SET_FLOAT_WORD(b
,hb
); /* b <- |b| */
35 if((ha
-hb
)>0xf000000L
) {return a
+b
;} /* x/y > 2**30 */
37 if(ha
> 0x58800000L
) { /* a>2**50 */
38 if(ha
>= 0x7f800000L
) { /* Inf or NaN */
39 w
= a
+b
; /* for sNaN */
40 if(ha
== 0x7f800000L
) w
= a
;
41 if(hb
== 0x7f800000L
) w
= b
;
44 /* scale a and b by 2**-60 */
45 ha
-= 0x5d800000L
; hb
-= 0x5d800000L
; k
+= 60;
49 if(hb
< 0x26800000L
) { /* b < 2**-50 */
50 if(hb
<= 0x007fffffL
) { /* subnormal b or 0 */
52 SET_FLOAT_WORD(t1
,0x3f000000L
); /* t1=2^126 */
56 } else { /* scale a and b by 2^60 */
57 ha
+= 0x5d800000; /* a *= 2^60 */
58 hb
+= 0x5d800000; /* b *= 2^60 */
64 /* medium size a and b */
67 SET_FLOAT_WORD(t1
,ha
&0xfffff000L
);
69 w
= sqrtf(t1
*t1
-(b
*(-b
)-t2
*(a
+t1
)));
72 SET_FLOAT_WORD(y1
,hb
&0xfffff000L
);
74 SET_FLOAT_WORD(t1
,ha
+0x00800000L
);
76 w
= sqrtf(t1
*y1
-(w
*(-w
)-(t1
*y2
+t2
*b
)));
79 SET_FLOAT_WORD(t1
,0x3f800000L
+(k
<<23));