casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QMath.h
Go to the documentation of this file.
1 //# QMath.h: Mathematical operations for the Quantum class.
2 //# Copyright (C) 1994,1995,1996,1998,1999,2000,2004
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_QMATH_H
29 #define CASA_QMATH_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Typedefs
41 
42 // <summary>
43 // Mathematical operations for the Quantum class.
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tQuantum">
49 // </reviewed>
50 //
51 // <prerequisite>
52 // <li> <linkto class=Unit>Unit</linkto>
53 // <li> <linkto class=Quantum>Quantum</linkto>
54 // </prerequisite>
55 //
56 // <etymology>
57 // QMath derived from Quantum Mathematical functions
58 // </etymology>
59 //
60 // <synopsis>
61 // Quantities are values with a unit. Their basic specification can be one of
62 // two forms:
63 // <srcblock>
64 // Quantity( Double value, String unit); // or: Unit unit
65 // Quantum<Type> ( Type value, String unit) // or: Unit unit
66 // </srcblock>
67 //
68 // A unit is a string of known unit fields separated
69 // by a space or a . (to indicate multiply) or a / (to indicate divide).
70 // See the <linkto class=Unit>Unit</linkto> class for details.
71 // Example: km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
72 //
73 // This file defines the mathematical operations that can be done on
74 // <linkto class=Quantum><src>Quantum<T></src></linkto>.
75 //
76 // They can be subdivided into various groupings:
77 // <ul>
78 // <li> <linkto file="QMath.h#prefix">Unary operations</linkto>
79 // <li> <linkto file="QMath.h#in-place">In place arithmetic functions: left hand side changed in place</linkto>
80 // <li> <linkto file="QMath.h#math">Arithmetic functions: return <src>Quantum<T></src></linkto>
81 // <li> <linkto file="QMath.h#arithmetic">Some useful arithmetic (linear) functions</linkto>
82 // <li> <linkto file="QMath.h#trigonometric">Trigonometric functions</linkto>
83 // <li> <linkto file="QMath.h#foreign">Functions to implement integer ceil/floor</linkto>
84 // </ul>
85 //
86 // The operations/functions defined are:
87 // <ul>
88 // <li> unary <src>+(Quantum<T>)</src>
89 // <li> unary <src>-(Quantum<T>)</src>
90 // <li> <src>+=Quantum<T>; +=T; -=Quantum<T>; -=T;</src>
91 // <li> <src>*=Quantum<T>, *=T; /=Quantum<T>; /=T;</src>
92 // <li> <src>+,-,*,/</src> for <src>Quantum<T>,Quantum<T>; T,Quantum<T>; Quantum<T>,T;</src>
93 // <li> <src>abs, ceil, floor(Quantum<T>)</src>
94 // <li> <src>pow(Quantum<T>, Int);</src>
95 // <li> <src>sin, cos, tan(Quantum<T>)</src> with proper unit handling
96 // <li> <src>asin, acos, atan, atan2(Quantum<T>)</src> with proper unit handling
97 // <li> <src>log, log10, exp, root, sqrt</src> with proper unit handling
98 // </ul>
99 // <note role=warning>
100 // Some operators are implemented as member functions, and can be found in the
101 // <linkto class=Quantum>Quantum</linkto> class.
102 // </note>
103 // </synopsis>
104 //
105 // <motivation>
106 // To separate the mathematical operations from Quantum.
107 // </motivation>
108 //
109 // <todo asof="941201">
110 // <li> Some inlining (did not work first go)
111 // </todo>
112 
113 // <linkfrom anchor="Quantum mathematical operations" classes="Quantum">
114 // <here>Quantum mathematical operations</here> -- Mathematical operations
115 // for the Quantum class.
116 // </linkfrom>
117 
118 // <group name="Quantum mathematical operations">
120 
121 // Unary operations
122 // <group name="prefix">
123 // See <linkto class=Quantum>Quantum</linkto> class
124 // </group>
125 
126 
127 // In place arithmetic functions: left hand side changed in place
128 // <thrown>
129 // <li> AipsError if non-conforming units (+ and -)
130 // <li> AipsError if illegal result unit (* and /; programming error)
131 // </thrown>
132 // <group name="in-place">
133 // See <linkto class=Quantum>Quantum</linkto> class
134 // </group>
135 
136 
137 // Arithmetic operators: return Quantum<T>
138 // <thrown>
139 // <li> AipsError if non-conforming units (+ and -)
140 // </thrown>
141 // <group name="math">
142 // See <linkto class=Quantum>Quantum</linkto> class for equal argument types
143 template <class Qtype>
144 Quantum<Qtype> operator+(const Quantum<Qtype> &left, const Qtype &other);
145 template <class Qtype>
146 Quantum<Qtype> operator+(const Qtype &left, const Quantum<Qtype> &other);
147 template <class Qtype>
148 Quantum<Qtype> operator-(const Quantum<Qtype> &left, const Qtype &other);
149 template <class Qtype>
150 Quantum<Qtype> operator-(const Qtype &left, const Quantum<Qtype> &other);
151 template <class Qtype>
152 Quantum<Qtype> operator*(const Quantum<Qtype> &left, const Qtype &other);
153 template <class Qtype>
154 Quantum<Qtype> operator*(const Qtype &left, const Quantum<Qtype> &other);
155 template <class Qtype>
156 Quantum<Qtype> operator/(const Quantum<Qtype> &left, const Qtype &other);
157 template <class Qtype>
158 Quantum<Qtype> operator/(const Qtype &left, const Quantum<Qtype> &other);
159 // </group>
160 
161 
162 // Some useful arithmetic (linear) functions
163 // <group name="arithmetic">
164 // Return the Quantum raised to specified power; take the (integer) root;
165 // and integerization
166 // <thrown>
167 // <li> AipsError if power exponent too large (abs > 100)
168 // <li> AipsError if root exponent zero
169 // </thrown>
170 template <class Qtype>
171 Quantum<Qtype> pow(const Quantum<Qtype> &left, Int p);
172 template <class Qtype>
173 Quantum<Qtype> root(const Quantum<Qtype> &left, Int p);
174 template <class Qtype>
175 Quantum<Qtype> sqrt(const Quantum<Qtype> &left);
176 template <class Qtype>
177 Quantum<Qtype> abs(const Quantum<Qtype> &left);
178 template <class Qtype>
179 Quantum<Qtype> ceil(const Quantum<Qtype> &left);
180 template <class Qtype>
181 Quantum<Qtype> floor(const Quantum<Qtype> &left);
182 // </group>
183 
184 
185 // Trigonometric and exponential functions
186 // For direct functions input should be in angles, output will be empty units.
187 // For inverse functions input should be empty, output in radians
188 // <thrown>
189 // <li> AipsError if incorrect units. I.e. non-angle for direct functions,
190 // non-empty for inverse functions; non-empty for exp and log
191 // </thrown>
192 // <group name="trigonometric">
193 template <class Qtype>
194 Quantum<Qtype> sin(const Quantum<Qtype> &left);
195 template <class Qtype>
196 Quantum<Qtype> cos(const Quantum<Qtype> &left);
197 template <class Qtype>
198 Quantum<Qtype> tan(const Quantum<Qtype> &left);
199 template <class Qtype>
200 Quantum<Qtype> asin(const Quantum<Qtype> &left);
201 template <class Qtype>
202 Quantum<Qtype> acos(const Quantum<Qtype> &left);
203 template <class Qtype>
204 Quantum<Qtype> atan(const Quantum<Qtype> &left);
205 template <class Qtype>
206 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
207 template <class Qtype>
208 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Qtype &other);
209 template <class Qtype>
210 Quantum<Qtype> atan2(const Qtype &left, const Quantum<Qtype> &other);
211 template <class Qtype>
212 Quantum<Qtype> log(const Quantum<Qtype> &left);
213 template <class Qtype>
214 Quantum<Qtype> log10(const Quantum<Qtype> &left);
215 template <class Qtype>
216 Quantum<Qtype> exp(const Quantum<Qtype> &left);
217 // </group>
218 
219 
220 // min and max
221 template <class Qtype>
222 Quantum<Qtype> min(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
223 template <class Qtype>
224 Quantum<Qtype> max(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
225 
226 
227 // Functions to implement integer ceil/floor and others
228 // <group name="foreign">
229 Int ceil(const Int &val);
230 Int floor(const Int &val);
237 Array<Int> operator *(const Array<Int> &in, Double f);
238 Array<Int> operator /(const Array<Int> &in, Double f);
239 // </group>
240 //# Inline Implementations
241 
242 // </group>
243 
244 
245 } //# NAMESPACE CASACORE - END
246 
247 #ifndef CASACORE_NO_AUTO_TEMPLATES
248 #include <casacore/casa/Quanta/QMath.tcc>
249 #endif //# CASACORE_NO_AUTO_TEMPLATES
250 #endif
LatticeExprNode log10(const LatticeExprNode &expr)
int Int
Definition: aipstype.h:50
LatticeExprNode log(const LatticeExprNode &expr)
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode exp(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
LatticeExprNode cos(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
double Double
Definition: aipstype.h:55
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type...
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode tan(const LatticeExprNode &expr)
LatticeExprNode atan(const LatticeExprNode &expr)
Quantities (i.e. dimensioned values)
Definition: MeasValue.h:41
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode acos(const LatticeExprNode &expr)
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.