Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_math.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003,2005 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 /*
24  * mathematical odds and ends.
25  */
26
27 #ifndef _GR_MATH_H_
28 #define _GR_MATH_H_
29
30 #include <gr_complex.h>
31
32 long gr_gcd (long m, long n);
33
34 // returns a non-zero value if value is "not-a-number" (NaN), and 0 otherwise
35 int gr_isnan (double value);
36
37 // returns a non-zero value if the value of x has its sign bit set.
38 //
39 // This  is  not  the  same  as `x < 0.0', because IEEE 754 floating point
40 // allows zero to be signed.  The comparison `-0.0 < 0.0'  is  false,  but
41 // `gr_signbit (-0.0)' will return a nonzero value.
42
43 int gr_signbit (double x);
44   
45 /*!
46  * \brief Fast arc tangent using table lookup and linear interpolation
47  *
48  * \param y component of input vector
49  * \param x component of input vector
50  * \returns float angle angle of vector (x, y) in radians
51  *
52  * This function calculates the angle of the vector (x,y) based on a
53  * table lookup and linear interpolation. The table uses a 256 point
54  * table covering -45 to +45 degrees and uses symetry to determine the
55  * final angle value in the range of -180 to 180 degrees. Note that
56  * this function uses the small angle approximation for values close
57  * to zero. This routine calculates the arc tangent with an average
58  * error of +/- 0.045 degrees.
59  */
60 float gr_fast_atan2f(float y, float x);
61
62 static inline float gr_fast_atan2f(gr_complex z) 
63
64   return gr_fast_atan2f(z.imag(), z.real()); 
65 }
66
67 #endif /* _GR_MATH_H_ */