casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QMath.h
Go to the documentation of this file.
00001 //# QMath.h: Mathematical operations for the Quantum class.
00002 //# Copyright (C) 1994,1995,1996,1998,1999,2000,2004
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: QMath.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_QMATH_H
00029 #define CASA_QMATH_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/BasicSL/Complex.h>
00035 #include <casa/Quanta/Quantum.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 template <class T> class Array;
00041 
00042 //# Typedefs
00043 
00044 // <summary>
00045 //   Mathematical operations for the Quantum class.
00046 // </summary>
00047 
00048 // <use visibility=export>
00049 
00050 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tQuantum">
00051 //
00052 // <prerequisite>
00053 //   <li> <linkto class=Unit>Unit</linkto>
00054 //   <li> <linkto class=Quantum>Quantum</linkto>
00055 // </prerequisite>
00056 //
00057 // <etymology>
00058 // QMath derived from Quantum Mathematical functions
00059 // </etymology>
00060 //
00061 // <synopsis> 
00062 // Quantities are values with a unit. Their basic specification can be one of
00063 // two forms:
00064 // <srcblock>
00065 // Quantity( Double value, String unit);        // or: Unit unit
00066 // Quantum<Type> ( Type value, String unit)     // or: Unit unit
00067 // </srcblock>
00068 //
00069 // A unit is a string of known unit fields separated
00070 // by 'space' or '.' (to indicate multiply) or '/' (to indicate divide).
00071 // See the <linkto class=Unit>Unit</linkto> class for details.
00072 // Example: km/s/(Mpc.s)2  is identical to km.s-1.Mpc-2.s-2
00073 //
00074 // This file defines the mathematical operations that can be done on
00075 // <linkto class=Quantum><src>Quantum<T></src></linkto>.
00076 //
00077 // They can be subdivided into various groupings:
00078 // <ul>
00079 //   <li> <linkto file="QMath.h#prefix">Unary operations</linkto>
00080 //   <li> <linkto file="QMath.h#in-place">In place arithmetic functions: left hand side changed in place</linkto>
00081 //   <li> <linkto file="QMath.h#math">Arithmetic functions: return <src>Quantum<T></src></linkto>
00082 //   <li> <linkto file="QMath.h#arithmetic">Some useful arithmetic (linear) functions</linkto>
00083 //   <li> <linkto file="QMath.h#trigonometric">Trigonometric functions</linkto>
00084 //   <li> <linkto file="QMath.h#foreign">Functions to implement integer ceil/floor</linkto>
00085 // </ul>
00086 //
00087 // The operations/functions defined are:
00088 // <ul>
00089 //   <li> unary <src>+(Quantum<T>)</src>
00090 //   <li> unary <src>-(Quantum<T>)</src>
00091 //   <li> <src>+=Quantum<T>; +=T; -=Quantum<T>; -=T;</src>
00092 //   <li> <src>*=Quantum<T>, *=T; /=Quantum<T>; /=T;</src>
00093 //   <li> <src>+/-/*//</src> for <src>Quantum<T>,Quantum<T>; T,Quantum<T>; Quantum<T>,T;</src>
00094 //   <li> <src>abs, ceil, floor(Quantum<T>)</src>
00095 //   <li> <src>pow(Quantum<T>, Int);</src>
00096 //   <li> <src>sin, cos, tan(Quantum<T>)</src> with proper unit handling
00097 //   <li> <src>asin, acos, atan, atan2(Quantum<T>)</src> with proper unit handling
00098 //   <li> <src>log, log10, exp, root, sqrt</src> with proper unit handling
00099 // </ul>
00100 // <note role=warning>
00101 // Some operators are implemented as member functions, and can be found in the
00102 // <linkto class=Quantum>Quantum</linkto> class.
00103 // </note>
00104 // </synopsis> 
00105 //
00106 // <motivation>
00107 // To separate the mathematical operations from Quantum.
00108 // </motivation>
00109 //
00110 // <todo asof="941201">
00111 //   <li> Some inlining (did not work first go)
00112 // </todo>
00113 
00114 // <linkfrom anchor="Quantum mathematical operations" classes="Quantum">
00115 //   <here>Quantum mathematical operations</here> -- Mathematical operations
00116 //   for the Quantum class.
00117 // </linkfrom>
00118 
00119 // <group name="Quantum mathematical operations">
00120 
00121 
00122 // Unary operations
00123 // <group name="prefix">
00124 // See <linkto class=Quantum>Quantum</linkto> class
00125 // </group>
00126 
00127 
00128 // In place arithmetic functions: left hand side changed in place
00129 // <thrown>
00130 //   <li> AipsError if non-conforming units (+ and -)
00131 //   <li> AipsError if illegal result unit (* and /; programming error)
00132 // </thrown>
00133 // <group name="in-place">
00134 // See <linkto class=Quantum>Quantum</linkto> class
00135 // </group>
00136 
00137 
00138 // Arithmetic operators: return Quantum<T>
00139 // <thrown>
00140 //   <li> AipsError if non-conforming units (+ and -)
00141 // </thrown>
00142 // <group name="math">
00143 // See <linkto class=Quantum>Quantum</linkto> class for equal argument types
00144 template <class Qtype>
00145 Quantum<Qtype> operator+(const Quantum<Qtype> &left, const Qtype &other);
00146 template <class Qtype>
00147 Quantum<Qtype> operator+(const Qtype &left, const Quantum<Qtype> &other);
00148 template <class Qtype>
00149 Quantum<Qtype> operator-(const Quantum<Qtype> &left, const Qtype &other);
00150 template <class Qtype>
00151 Quantum<Qtype> operator-(const Qtype &left, const Quantum<Qtype> &other);
00152 template <class Qtype>
00153 Quantum<Qtype> operator*(const Quantum<Qtype> &left, const Qtype &other);
00154 template <class Qtype>
00155 Quantum<Qtype> operator*(const Qtype &left, const Quantum<Qtype> &other);
00156 template <class Qtype>
00157 Quantum<Qtype> operator/(const Quantum<Qtype> &left, const Qtype &other);
00158 template <class Qtype>
00159 Quantum<Qtype> operator/(const Qtype &left, const Quantum<Qtype> &other);
00160 // </group>
00161 
00162 
00163 // Some useful arithmetic (linear) functions
00164 // <group name="arithmetic">
00165 // Return the Quantum raised to specified power; take the (integer) root;
00166 // and integerization
00167 // <thrown>
00168 //   <li> AipsError if power exponent too large (abs > 100)
00169 //   <li> AipsError if root exponent zero
00170 // </thrown>
00171 template <class Qtype>
00172 Quantum<Qtype> pow(const Quantum<Qtype> &left, Int p);
00173 template <class Qtype>
00174 Quantum<Qtype> root(const Quantum<Qtype> &left, Int p);
00175 template <class Qtype>
00176 Quantum<Qtype> sqrt(const Quantum<Qtype> &left);
00177 template <class Qtype>
00178 Quantum<Qtype> abs(const Quantum<Qtype> &left);
00179 template <class Qtype>
00180 Quantum<Qtype> ceil(const Quantum<Qtype> &left);
00181 template <class Qtype>
00182 Quantum<Qtype> floor(const Quantum<Qtype> &left);
00183 // </group>
00184 
00185 
00186 // Trigonometric and exponential functions
00187 // For direct functions input should be in angles, output will be empty units.
00188 // For inverse functions input should be empty, output in radians
00189 // <thrown>
00190 //    <li> AipsError if incorrect units. I.e. non-angle for direct functions,
00191 //              non-empty for inverse functions; non-empty for exp and log
00192 // </thrown>
00193 // <group name="trigonometric">
00194 template <class Qtype>
00195 Quantum<Qtype> sin(const Quantum<Qtype> &left);
00196 template <class Qtype>
00197 Quantum<Qtype> cos(const Quantum<Qtype> &left);
00198 template <class Qtype>
00199 Quantum<Qtype> tan(const Quantum<Qtype> &left);
00200 template <class Qtype>
00201 Quantum<Qtype> asin(const Quantum<Qtype> &left);
00202 template <class Qtype>
00203 Quantum<Qtype> acos(const Quantum<Qtype> &left);
00204 template <class Qtype>
00205 Quantum<Qtype> atan(const Quantum<Qtype> &left);
00206 template <class Qtype>
00207 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
00208 template <class Qtype>
00209 Quantum<Qtype> atan2(const Quantum<Qtype> &left, const Qtype &other);
00210 template <class Qtype>
00211 Quantum<Qtype> atan2(const Qtype &left, const Quantum<Qtype> &other);
00212 template <class Qtype>
00213 Quantum<Qtype> log(const Quantum<Qtype> &left);
00214 template <class Qtype>
00215 Quantum<Qtype> log10(const Quantum<Qtype> &left);
00216 template <class Qtype>
00217 Quantum<Qtype> exp(const Quantum<Qtype> &left);
00218 // </group>
00219 
00220 
00221 // min and max
00222 template <class Qtype>
00223 Quantum<Qtype> min(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
00224 template <class Qtype>
00225 Quantum<Qtype> max(const Quantum<Qtype> &left, const Quantum<Qtype> &other);
00226 
00227 
00228 // Functions to implement integer ceil/floor and others
00229 // <group name="foreign">
00230 Int ceil(const Int &val);
00231 Int floor(const Int &val);
00232 Float real(const Float &val);
00233 Double real(const Double&val);
00234 Array<Complex> operator *(const Array<Complex> &in, Double f);
00235 Array<Complex> operator /(const Array<Complex> &in, Double f);
00236 Array<DComplex> operator *(const Array<DComplex> &in, Double f);
00237 Array<DComplex> operator /(const Array<DComplex> &in, Double f);
00238 Array<Float> operator *(const Array<Float> &in, Double f);
00239 Array<Float> operator /(const Array<Float> &in, Double f);
00240 Array<Int> operator *(const Array<Int> &in, Double f);
00241 Array<Int> operator /(const Array<Int> &in, Double f);
00242 // </group>
00243 //# Inline Implementations
00244 
00245 // </group>
00246 
00247 
00248 } //# NAMESPACE CASA - END
00249 
00250 #ifndef CASACORE_NO_AUTO_TEMPLATES
00251 #include <casa/Quanta/QMath.tcc>
00252 #endif //# CASACORE_NO_AUTO_TEMPLATES
00253 #endif