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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libm/] [current/] [src/] [double/] [ieee754-core/] [e_atan2.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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