Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3362 Serge 1
/* ef_hypot.c -- float version of e_hypot.c.
2
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3
 */
4
 
5
/*
6
 * ====================================================
7
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8
 *
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
 * ====================================================
14
 */
15
 
16
#include "fdlibm.h"
17
 
18
#ifdef __STDC__
19
	float __ieee754_hypotf(float x, float y)
20
#else
21
	float __ieee754_hypotf(x,y)
22
	float x, y;
23
#endif
24
{
25
	float a=x,b=y,t1,t2,y1,y2,w;
26
	__int32_t j,k,ha,hb;
27
 
28
	GET_FLOAT_WORD(ha,x);
29
	ha &= 0x7fffffffL;
30
	GET_FLOAT_WORD(hb,y);
31
	hb &= 0x7fffffffL;
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 */
36
	k=0;
37
	if(ha > 0x58800000L) {	/* a>2**50 */
38
	   if(!FLT_UWORD_IS_FINITE(ha)) {	/* Inf or NaN */
39
	       w = a+b;			/* for sNaN */
40
	       if(FLT_UWORD_IS_INFINITE(ha)) w = a;
41
	       if(FLT_UWORD_IS_INFINITE(hb)) w = b;
42
	       return w;
43
	   }
44
	   /* scale a and b by 2**-68 */
45
	   ha -= 0x22000000L; hb -= 0x22000000L;	k += 68;
46
	   SET_FLOAT_WORD(a,ha);
47
	   SET_FLOAT_WORD(b,hb);
48
	}
49
	if(hb < 0x26800000L) {	/* b < 2**-50 */
50
	    if(FLT_UWORD_IS_ZERO(hb)) {
51
	        return a;
52
	    } else if(FLT_UWORD_IS_SUBNORMAL(hb)) {
53
		SET_FLOAT_WORD(t1,0x7e800000L);	/* t1=2^126 */
54
		b *= t1;
55
		a *= t1;
56
		k -= 126;
57
	    } else {		/* scale a and b by 2^68 */
58
	        ha += 0x22000000; 	/* a *= 2^68 */
59
		hb += 0x22000000;	/* b *= 2^68 */
60
		k -= 68;
61
		SET_FLOAT_WORD(a,ha);
62
		SET_FLOAT_WORD(b,hb);
63
	    }
64
	}
65
    /* medium size a and b */
66
	w = a-b;
67
	if (w>b) {
68
	    SET_FLOAT_WORD(t1,ha&0xfffff000L);
69
	    t2 = a-t1;
70
	    w  = __ieee754_sqrtf(t1*t1-(b*(-b)-t2*(a+t1)));
71
	} else {
72
	    a  = a+a;
73
	    SET_FLOAT_WORD(y1,hb&0xfffff000L);
74
	    y2 = b - y1;
75
	    SET_FLOAT_WORD(t1,ha+0x00800000L);
76
	    t2 = a - t1;
77
	    w  = __ieee754_sqrtf(t1*y1-(w*(-w)-(t1*y2+t2*b)));
78
	}
79
	if(k!=0) {
80
	    SET_FLOAT_WORD(t1,0x3f800000L+(k<<23));
81
	    return t1*w;
82
	} else return w;
83
}