casa  5.7.0-16
 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>
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 //# Forward Declarations
40 template <class T> class Array;
41 
42 //# Typedefs
43 
44 // <summary>
45 // Mathematical operations for the Quantum class.
46 // </summary>
47 
48 // <use visibility=export>
49 
50 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tQuantum">
51 //
52 // <prerequisite>
53 // <li> <linkto class=Unit>Unit</linkto>
54 // <li> <linkto class=Quantum>Quantum</linkto>
55 // </prerequisite>
56 //
57 // <etymology>
58 // QMath derived from Quantum Mathematical functions
59 // </etymology>
60 //
61 // <synopsis>
62 // Quantities are values with a unit. Their basic specification can be one of
63 // two forms:
64 // <srcblock>
65 // Quantity( Double value, String unit); // or: Unit unit
66 // Quantum<Type> ( Type value, String unit) // or: Unit unit
67 // </srcblock>
68 //
69 // A unit is a string of known unit fields separated
70 // by 'space' or '.' (to indicate multiply) or '/' (to indicate divide).
71 // See the <linkto class=Unit>Unit</linkto> class for details.
72 // Example: km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
73 //
74 // This file defines the mathematical operations that can be done on
75 // <linkto class=Quantum><src>Quantum<T></src></linkto>.
76 //
77 // They can be subdivided into various groupings:
78 // <ul>
79 // <li> <linkto file="QMath.h#prefix">Unary operations</linkto>
80 // <li> <linkto file="QMath.h#in-place">In place arithmetic functions: left hand side changed in place</linkto>
81 // <li> <linkto file="QMath.h#math">Arithmetic functions: return <src>Quantum<T></src></linkto>
82 // <li> <linkto file="QMath.h#arithmetic">Some useful arithmetic (linear) functions</linkto>
83 // <li> <linkto file="QMath.h#trigonometric">Trigonometric functions</linkto>
84 // <li> <linkto file="QMath.h#foreign">Functions to implement integer ceil/floor</linkto>
85 // </ul>
86 //
87 // The operations/functions defined are:
88 // <ul>
89 // <li> unary <src>+(Quantum<T>)</src>
90 // <li> unary <src>-(Quantum<T>)</src>
91 // <li> <src>+=Quantum<T>; +=T; -=Quantum<T>; -=T;</src>
92 // <li> <src>*=Quantum<T>, *=T; /=Quantum<T>; /=T;</src>
93 // <li> <src>+/-/*//</src> for <src>Quantum<T>,Quantum<T>; T,Quantum<T>; Quantum<T>,T;</src>
94 // <li> <src>abs, ceil, floor(Quantum<T>)</src>
95 // <li> <src>pow(Quantum<T>, Int);</src>
96 // <li> <src>sin, cos, tan(Quantum<T>)</src> with proper unit handling
97 // <li> <src>asin, acos, atan, atan2(Quantum<T>)</src> with proper unit handling
98 // <li> <src>log, log10, exp, root, sqrt</src> with proper unit handling
99 // </ul>
100 // <note role=warning>
101 // Some operators are implemented as member functions, and can be found in the
102 // <linkto class=Quantum>Quantum</linkto> class.
103 // </note>
104 // </synopsis>
105 //
106 // <motivation>
107 // To separate the mathematical operations from Quantum.
108 // </motivation>
109 //
110 // <todo asof="941201">
111 // <li> Some inlining (did not work first go)
112 // </todo>
113 
114 // <linkfrom anchor="Quantum mathematical operations" classes="Quantum">
115 // <here>Quantum mathematical operations</here> -- Mathematical operations
116 // for the Quantum class.
117 // </linkfrom>
118 
119 // <group name="Quantum mathematical operations">
121 
122 // Unary operations
123 // <group name="prefix">
124 // See <linkto class=Quantum>Quantum</linkto> class
125 // </group>
126 
127 
128 // In place arithmetic functions: left hand side changed in place
129 // <thrown>
130 // <li> AipsError if non-conforming units (+ and -)
131 // <li> AipsError if illegal result unit (* and /; programming error)
132 // </thrown>
133 // <group name="in-place">
134 // See <linkto class=Quantum>Quantum</linkto> class
135 // </group>
136 
137 
138 // Arithmetic operators: return Quantum<T>
139 // <thrown>
140 // <li> AipsError if non-conforming units (+ and -)
141 // </thrown>
142 // <group name="math">
143 // See <linkto class=Quantum>Quantum</linkto> class for equal argument types
144 template <class Qtype>
145 Quantum<Qtype> operator+(const Quantum<Qtype> &left, const Qtype &other);
146 template <class Qtype>
147 Quantum<Qtype> operator+(const Qtype &left, const Quantum<Qtype> &other);
148 template <class Qtype>
149 Quantum<Qtype> operator-(const Quantum<Qtype> &left, const Qtype &other);
150 template <class Qtype>
151 Quantum<Qtype> operator-(const Qtype &left, const Quantum<Qtype> &other);
152 template <class Qtype>
153 Quantum<Qtype> operator*(const Quantum<Qtype> &left, const Qtype &other);
154 template <class Qtype>
155 Quantum<Qtype> operator*(const Qtype &left, const Quantum<Qtype> &other);
156 template <class Qtype>
157 Quantum<Qtype> operator/(const Quantum<Qtype> &left, const Qtype &other);
158 template <class Qtype>
159 Quantum<Qtype> operator/(const Qtype &left, const Quantum<Qtype> &other);
160 // </group>
161 
162 
163 // Some useful arithmetic (linear) functions
164 // <group name="arithmetic">
165 // Return the Quantum raised to specified power; take the (integer) root;
166 // and integerization
167 // <thrown>
168 // <li> AipsError if power exponent too large (abs > 100)
169 // <li> AipsError if root exponent zero
170 // </thrown>
171 template <class Qtype>
172 Quantum<Qtype> pow(const Quantum<Qtype> &left, Int p);
173 template <class Qtype>
174 Quantum<Qtype> root(const Quantum<Qtype> &left, Int p);
175 template <class Qtype>
176 Quantum<Qtype> sqrt(const Quantum<Qtype> &left);
177 template <class Qtype>
178 Quantum<Qtype> abs(const Quantum<Qtype> &left);
179 template <class Qtype>
180 Quantum<Qtype> ceil(const Quantum<Qtype> &left);
181 template <class Qtype>
182 Quantum<Qtype> floor(const Quantum<Qtype> &left);
183 // </group>
184 
185 
186 // Trigonometric and exponential functions
187 // For direct functions input should be in angles, output will be empty units.
188 // For inverse functions input should be empty, output in radians
189 // <thrown>
190 // <li> AipsError if incorrect units. I.e. non-angle for direct functions,
191 // non-empty for inverse functions; non-empty for exp and log
192 // </thrown>
193 // <group name="trigonometric">
194 template <class Qtype>
195 Quantum<Qtype> sin(const Quantum<Qtype> &left);
196 template <class Qtype>
197 Quantum<Qtype> cos(const Quantum<Qtype> &left);
198 template <class Qtype>
199 Quantum<Qtype> tan(const Quantum<Qtype> &left);
200 template <class Qtype>
201 Quantum<Qtype> asin(const Quantum<Qtype> &left);
202 template <class Qtype>
203 Quantum<Qtype> acos(const Quantum<Qtype> &left);
204 template <class Qtype>
205 Quantum<Qtype> atan(const Quantum<Qtype> &left);
206 template <class Qtype>
207 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
208 template <class Qtype>
209 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Qtype &other);
210 template <class Qtype>
211 Quantum<Qtype> atan2(const Qtype &left, const Quantum<Qtype> &other);
212 template <class Qtype>
213 Quantum<Qtype> log(const Quantum<Qtype> &left);
214 template <class Qtype>
215 Quantum<Qtype> log10(const Quantum<Qtype> &left);
216 template <class Qtype>
217 Quantum<Qtype> exp(const Quantum<Qtype> &left);
218 // </group>
219 
220 
221 // min and max
222 template <class Qtype>
223 Quantum<Qtype> min(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
224 template <class Qtype>
225 Quantum<Qtype> max(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
226 
227 
228 // Functions to implement integer ceil/floor and others
229 // <group name="foreign">
230 Int ceil(const Int &val);
231 Int floor(const Int &val);
238 Array<Int> operator *(const Array<Int> &in, Double f);
239 Array<Int> operator /(const Array<Int> &in, Double f);
240 // </group>
241 //# Inline Implementations
242 
243 // </group>
244 
245 
246 } //# NAMESPACE CASACORE - END
247 
248 #ifndef CASACORE_NO_AUTO_TEMPLATES
249 #include <casacore/casa/Quanta/QMath.tcc>
250 #endif //# CASACORE_NO_AUTO_TEMPLATES
251 #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)
MVEarthMagnetic operator*(const RotMatrix &left, const MVEarthMagnetic &right)
Rotate a EarthMagnetic vector with rotation matrix and other multiplications.
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: QuantumHolder.h:44
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)
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42