Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / msun / src / e_hypotf.c
1 /* e_hypotf.c -- float version of e_hypot.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  *
4  * $FreeBSD: src/lib/msun/src/e_hypotf.c,v 1.7 1999/08/28 00:06:32 peter Exp $
5  * $DragonFly: src/lib/msun/src/Attic/e_hypotf.c,v 1.2 2003/06/17 04:26:52 dillon Exp $
6  */
7
8 /*
9  * ====================================================
10  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11  *
12  * Developed at SunPro, a Sun Microsystems, Inc. business.
13  * Permission to use, copy, modify, and distribute this
14  * software is freely granted, provided that this notice
15  * is preserved.
16  * ====================================================
17  */
18
19 #include "math.h"
20 #include "math_private.h"
21
22 #ifdef __STDC__
23         float __ieee754_hypotf(float x, float y)
24 #else
25         float __ieee754_hypot(x,y)
26         float x, y;
27 #endif
28 {
29         float a=x,b=y,t1,t2,y1,y2,w;
30         int32_t j,k,ha,hb;
31
32         GET_FLOAT_WORD(ha,x);
33         ha &= 0x7fffffff;
34         GET_FLOAT_WORD(hb,y);
35         hb &= 0x7fffffff;
36         if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
37         SET_FLOAT_WORD(a,ha);   /* a <- |a| */
38         SET_FLOAT_WORD(b,hb);   /* b <- |b| */
39         if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
40         k=0;
41         if(ha > 0x58800000) {   /* a>2**50 */
42            if(ha >= 0x7f800000) {       /* Inf or NaN */
43                w = a+b;                 /* for sNaN */
44                if(ha == 0x7f800000) w = a;
45                if(hb == 0x7f800000) w = b;
46                return w;
47            }
48            /* scale a and b by 2**-68 */
49            ha -= 0x22000000; hb -= 0x22000000;  k += 68;
50            SET_FLOAT_WORD(a,ha);
51            SET_FLOAT_WORD(b,hb);
52         }
53         if(hb < 0x26800000) {   /* b < 2**-50 */
54             if(hb <= 0x007fffff) {      /* subnormal b or 0 */
55                 if(hb==0) return a;
56                 SET_FLOAT_WORD(t1,0x7e800000);  /* t1=2^126 */
57                 b *= t1;
58                 a *= t1;
59                 k -= 126;
60             } else {            /* scale a and b by 2^68 */
61                 ha += 0x22000000;       /* a *= 2^68 */
62                 hb += 0x22000000;       /* b *= 2^68 */
63                 k -= 68;
64                 SET_FLOAT_WORD(a,ha);
65                 SET_FLOAT_WORD(b,hb);
66             }
67         }
68     /* medium size a and b */
69         w = a-b;
70         if (w>b) {
71             SET_FLOAT_WORD(t1,ha&0xfffff000);
72             t2 = a-t1;
73             w  = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
74         } else {
75             a  = a+a;
76             SET_FLOAT_WORD(y1,hb&0xfffff000);
77             y2 = b - y1;
78             SET_FLOAT_WORD(t1,ha+0x00800000);
79             t2 = a - t1;
80             w  = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
81         }
82         if(k!=0) {
83             SET_FLOAT_WORD(t1,0x3f800000+(k<<23));
84             return t1*w;
85         } else return w;
86 }