HAMMER VFS - Major retooling of the refcount mechanics, and fix a deadlock
[dragonfly.git] / lib / libm / src / e_hypotf.c
blob906356228fb2e1b332721a2e62585d2673ca8f7d
1 /* e_hypotf.c -- float version of e_hypot.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
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
12 * is preserved.
13 * ====================================================
15 * $NetBSD: e_hypotf.c,v 1.8 2002/05/26 22:01:50 wiz Exp $
16 * $DragonFly: src/lib/libm/src/e_hypotf.c,v 1.1 2005/07/26 21:15:20 joerg Exp $
19 #include <math.h>
20 #include "math_private.h"
22 float
23 hypotf(float x, float y)
25 float a,b,t1,t2,y1_,y2,w;
26 int32_t j,k,ha,hb;
28 GET_FLOAT_WORD(ha,x);
29 ha &= 0x7fffffff;
30 GET_FLOAT_WORD(hb,y);
31 hb &= 0x7fffffff;
32 if(hb > ha) {j=ha;ha=hb;hb=j;}
33 SET_FLOAT_WORD(a,ha); /* a <- |a| */
34 SET_FLOAT_WORD(b,hb); /* b <- |b| */
35 if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
36 k=0;
37 if(ha > 0x58800000) { /* a>2**50 */
38 if(ha >= 0x7f800000) { /* Inf or NaN */
39 w = a+b; /* for sNaN */
40 if(ha == 0x7f800000) w = a;
41 if(hb == 0x7f800000) w = b;
42 return w;
44 /* scale a and b by 2**-60 */
45 ha -= 0x5d800000; hb -= 0x5d800000; k += 60;
46 SET_FLOAT_WORD(a,ha);
47 SET_FLOAT_WORD(b,hb);
49 if(hb < 0x26800000) { /* b < 2**-50 */
50 if(hb <= 0x007fffff) { /* subnormal b or 0 */
51 if(hb==0) return a;
52 SET_FLOAT_WORD(t1,0x3f000000); /* t1=2^126 */
53 b *= t1;
54 a *= t1;
55 k -= 126;
56 } else { /* scale a and b by 2^60 */
57 ha += 0x5d800000; /* a *= 2^60 */
58 hb += 0x5d800000; /* b *= 2^60 */
59 k -= 60;
60 SET_FLOAT_WORD(a,ha);
61 SET_FLOAT_WORD(b,hb);
64 /* medium size a and b */
65 w = a-b;
66 if (w>b) {
67 SET_FLOAT_WORD(t1,ha&0xfffff000);
68 t2 = a-t1;
69 w = sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
70 } else {
71 a = a+a;
72 SET_FLOAT_WORD(y1_,hb&0xfffff000);
73 y2 = b - y1_;
74 SET_FLOAT_WORD(t1,ha+0x00800000);
75 t2 = a - t1;
76 w = sqrtf(t1*y1_-(w*(-w)-(t1*y2+t2*b)));
78 if(k!=0) {
79 SET_FLOAT_WORD(t1,0x3f800000+(k<<23));
80 return t1*w;
81 } else return w;