Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* e_atan2f.c -- float version of e_atan2.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
#ifndef lint
17
static char rcsid[] = "$\Id: e_atan2f.c,v 1.2 1995/05/30 05:47:59 rgrimes Exp $";
18
#endif
19
 
20
#include "math.h"
21
#include "math_private.h"
22
 
23
#ifdef __STDC__
24
static const float
25
#else
26
static float
27
#endif
28
tiny  = 1.0e-30,
29
zero  = 0.0,
30
pi_o_4  = 7.8539818525e-01, /* 0x3f490fdb */
31
pi_o_2  = 1.5707963705e+00, /* 0x3fc90fdb */
32
pi      = 3.1415925026e+00, /* 0x40490fda */
33
pi_lo   = 1.5099578832e-07; /* 0x34222168 */
34
 
35
#ifdef __STDC__
36
        float __ieee754_atan2f(float y, float x)
37
#else
38
        float __ieee754_atan2f(y,x)
39
        float  y,x;
40
#endif
41
{
42
        float z;
43
        int32_t k,m,hx,hy,ix,iy;
44
 
45
        GET_FLOAT_WORD(hx,x);
46
        ix = hx&0x7fffffff;
47
        GET_FLOAT_WORD(hy,y);
48
        iy = hy&0x7fffffff;
49
        if((ix>0x7f800000)||
50
           (iy>0x7f800000))     /* x or y is NaN */
51
           return x+y;
52
        if(hx==0x3f800000) return atanf(y);   /* x=1.0 */
53
        m = ((hy>>31)&1)|((hx>>30)&2);  /* 2*sign(x)+sign(y) */
54
 
55
    /* when y = 0 */
56
        if(iy==0) {
57
            switch(m) {
58
                case 0:
59
                case 1: return y;       /* atan(+-0,+anything)=+-0 */
60
                case 2: return  pi+tiny;/* atan(+0,-anything) = pi */
61
                case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
62
            }
63
        }
64
    /* when x = 0 */
65
        if(ix==0) return (hy<0)?  -pi_o_2-tiny: pi_o_2+tiny;
66
 
67
    /* when x is INF */
68
        if(ix==0x7f800000) {
69
            if(iy==0x7f800000) {
70
                switch(m) {
71
                    case 0: return  pi_o_4+tiny;/* atan(+INF,+INF) */
72
                    case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
73
                    case 2: return  (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
74
                    case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
75
                }
76
            } else {
77
                switch(m) {
78
                    case 0: return  zero  ;     /* atan(+...,+INF) */
79
                    case 1: return -zero  ;     /* atan(-...,+INF) */
80
                    case 2: return  pi+tiny  ;  /* atan(+...,-INF) */
81
                    case 3: return -pi-tiny  ;  /* atan(-...,-INF) */
82
                }
83
            }
84
        }
85
    /* when y is INF */
86
        if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
87
 
88
    /* compute y/x */
89
        k = (iy-ix)>>23;
90
        if(k > 60) z=pi_o_2+(float)0.5*pi_lo;   /* |y/x| >  2**60 */
91
        else if(hx<0&&k<-60) z=0.0;     /* |y|/x < -2**60 */
92
        else z=atanf(fabsf(y/x));       /* safe to do y/x */
93
        switch (m) {
94
            case 0: return       z  ;   /* atan(+,+) */
95
            case 1: {
96
                      u_int32_t zh;
97
                      GET_FLOAT_WORD(zh,z);
98
                      SET_FLOAT_WORD(z,zh ^ 0x80000000);
99
                    }
100
                    return       z  ;   /* atan(-,+) */
101
            case 2: return  pi-(z-pi_lo);/* atan(+,-) */
102
            default: /* case 3 */
103
                    return  (z-pi_lo)-pi;/* atan(-,-) */
104
        }
105
}