OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libm/] [v2_0/] [src/] [double/] [ieee754-core/] [e_atan2.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//===========================================================================
2
//
3
//      e_atan2.c
4
//
5
//      Part of the standard mathematical function library
6
//
7
//===========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//===========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):   jlarmour
44
// Contributors:  jlarmour
45
// Date:        1998-02-13
46
// Purpose:     
47
// Description: 
48
// Usage:       
49
//
50
//####DESCRIPTIONEND####
51
//
52
//===========================================================================
53
 
54
// CONFIGURATION
55
 
56
#include <pkgconf/libm.h>   // Configuration header
57
 
58
// Include the Math library?
59
#ifdef CYGPKG_LIBM     
60
 
61
// Derived from code with the following copyright
62
 
63
 
64
/* @(#)e_atan2.c 1.3 95/01/18 */
65
/*
66
 * ====================================================
67
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
68
 *
69
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
70
 * Permission to use, copy, modify, and distribute this
71
 * software is freely granted, provided that this notice
72
 * is preserved.
73
 * ====================================================
74
 *
75
 */
76
 
77
/* __ieee754_atan2(y,x)
78
 * Method :
79
 *      1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
80
 *      2. Reduce x to positive by (if x and y are unexceptional):
81
 *              ARG (x+iy) = arctan(y/x)           ... if x > 0,
82
 *              ARG (x+iy) = pi - arctan[y/(-x)]   ... if x < 0,
83
 *
84
 * Special cases:
85
 *
86
 *      ATAN2((anything), NaN ) is NaN;
87
 *      ATAN2(NAN , (anything) ) is NaN;
88
 *      ATAN2(+-0, +(anything but NaN)) is +-0  ;
89
 *      ATAN2(+-0, -(anything but NaN)) is +-pi ;
90
 *      ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
91
 *      ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
92
 *      ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
93
 *      ATAN2(+-INF,+INF ) is +-pi/4 ;
94
 *      ATAN2(+-INF,-INF ) is +-3pi/4;
95
 *      ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
96
 *
97
 * Constants:
98
 * The hexadecimal values are the intended ones for the following
99
 * constants. The decimal values may be used, provided that the
100
 * compiler will convert from decimal to binary accurately enough
101
 * to produce the hexadecimal values shown.
102
 */
103
 
104
#include "mathincl/fdlibm.h"
105
 
106
static const double
107
tiny  = 1.0e-300,
108
zero  = 0.0,
109
pi_o_4  = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
110
pi_o_2  = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
111
pi      = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
112
pi_lo   = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
113
 
114
        double __ieee754_atan2(double y, double x)
115
{
116
        double z;
117
        int k,m,hx,hy,ix,iy;
118
        unsigned lx,ly;
119
 
120
        hx = CYG_LIBM_HI(x); ix = hx&0x7fffffff;
121
        lx = CYG_LIBM_LO(x);
122
        hy = CYG_LIBM_HI(y); iy = hy&0x7fffffff;
123
        ly = CYG_LIBM_LO(y);
124
        if(((ix|((lx|-lx)>>31))>0x7ff00000)||
125
           ((iy|((ly|-ly)>>31))>0x7ff00000))    /* x or y is NaN */
126
           return x+y;
127
        if(((hx-0x3ff00000)|lx)==0) return atan(y);   /* x=1.0 */
128
        m = ((hy>>31)&1)|((hx>>30)&2);  /* 2*sign(x)+sign(y) */
129
 
130
    /* when y = 0 */
131
        if((iy|ly)==0) {
132
            switch(m) {
133
                case 0:
134
                case 1: return y;       /* atan(+-0,+anything)=+-0 */
135
                case 2: return  pi+tiny;/* atan(+0,-anything) = pi */
136
                case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
137
            }
138
        }
139
    /* when x = 0 */
140
        if((ix|lx)==0) return (hy<0)?  -pi_o_2-tiny: pi_o_2+tiny;
141
 
142
    /* when x is INF */
143
        if(ix==0x7ff00000) {
144
            if(iy==0x7ff00000) {
145
                switch(m) {
146
                    case 0: return  pi_o_4+tiny;/* atan(+INF,+INF) */
147
                    case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
148
                    case 2: return  3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
149
                    case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
150
                }
151
            } else {
152
                switch(m) {
153
                    case 0: return  zero  ;     /* atan(+...,+INF) */
154
                    case 1: return -zero  ;     /* atan(-...,+INF) */
155
                    case 2: return  pi+tiny  ;  /* atan(+...,-INF) */
156
                    case 3: return -pi-tiny  ;  /* atan(-...,-INF) */
157
                }
158
            }
159
        }
160
    /* when y is INF */
161
        if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
162
 
163
    /* compute y/x */
164
        k = (iy-ix)>>20;
165
        if(k > 60) z=pi_o_2+0.5*pi_lo;  /* |y/x| >  2**60 */
166
        else if(hx<0&&k<-60) z=0.0;     /* |y|/x < -2**60 */
167
        else z=atan(fabs(y/x));         /* safe to do y/x */
168
        switch (m) {
169
            case 0: return       z  ;   /* atan(+,+) */
170
            case 1: CYG_LIBM_HI(z) ^= 0x80000000;
171
                    return       z  ;   /* atan(-,+) */
172
            case 2: return  pi-(z-pi_lo);/* atan(+,-) */
173
            default: /* case 3 */
174
                    return  (z-pi_lo)-pi;/* atan(-,-) */
175
        }
176
}
177
 
178
#endif // ifdef CYGPKG_LIBM     
179
 
180
// EOF e_atan2.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.