VM: munmap used by VM for itself is no longer used
[minix.git] / lib / libm / src / e_hypotf.c
blob23906617df9f1b5b5d379502d1d1d7d47e55e54b
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 * ====================================================
16 #include <sys/cdefs.h>
17 #if defined(LIBM_SCCS) && !defined(lint)
18 __RCSID("$NetBSD: e_hypotf.c,v 1.9 2008/04/25 22:21:53 christos Exp $");
19 #endif
21 #include "math.h"
22 #include "math_private.h"
24 float
25 __ieee754_hypotf(float x, float y)
27 float a=x,b=y,t1,t2,yy1,y2,w;
28 int32_t j,k,ha,hb;
30 GET_FLOAT_WORD(ha,x);
31 ha &= 0x7fffffff;
32 GET_FLOAT_WORD(hb,y);
33 hb &= 0x7fffffff;
34 if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
35 SET_FLOAT_WORD(a,ha); /* a <- |a| */
36 SET_FLOAT_WORD(b,hb); /* b <- |b| */
37 if((ha-hb)>0xf000000) {return a+b;} /* x/y > 2**30 */
38 k=0;
39 if(ha > 0x58800000) { /* a>2**50 */
40 if(ha >= 0x7f800000) { /* Inf or NaN */
41 w = a+b; /* for sNaN */
42 if(ha == 0x7f800000) w = a;
43 if(hb == 0x7f800000) w = b;
44 return w;
46 /* scale a and b by 2**-60 */
47 ha -= 0x5d800000; hb -= 0x5d800000; k += 60;
48 SET_FLOAT_WORD(a,ha);
49 SET_FLOAT_WORD(b,hb);
51 if(hb < 0x26800000) { /* b < 2**-50 */
52 if(hb <= 0x007fffff) { /* subnormal b or 0 */
53 if(hb==0) return a;
54 SET_FLOAT_WORD(t1,0x3f000000); /* t1=2^126 */
55 b *= t1;
56 a *= t1;
57 k -= 126;
58 } else { /* scale a and b by 2^60 */
59 ha += 0x5d800000; /* a *= 2^60 */
60 hb += 0x5d800000; /* b *= 2^60 */
61 k -= 60;
62 SET_FLOAT_WORD(a,ha);
63 SET_FLOAT_WORD(b,hb);
66 /* medium size a and b */
67 w = a-b;
68 if (w>b) {
69 SET_FLOAT_WORD(t1,ha&0xfffff000);
70 t2 = a-t1;
71 w = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
72 } else {
73 a = a+a;
74 SET_FLOAT_WORD(yy1,hb&0xfffff000);
75 y2 = b - yy1;
76 SET_FLOAT_WORD(t1,ha+0x00800000);
77 t2 = a - t1;
78 w = __ieee754_sqrtf(t1*yy1-(w*(-w)-(t1*y2+t2*b)));
80 if(k!=0) {
81 SET_FLOAT_WORD(t1,0x3f800000+(k<<23));
82 return t1*w;
83 } else return w;