![]() |
rtVTK
0.6.0
|
00001 00002 /****************************************************************************** 00003 * Copyright (c) 2012, Grove City College 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are 00008 * met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * * Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in 00015 * the documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * * Neither the name of Grove City College nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 */ 00035 00036 00037 #ifndef Math_Helpers_h 00038 #define Math_Helpers_h 00039 00040 #include <cmath> 00041 00042 #include <iostream> 00043 using std::ostream; 00044 using std::istream; 00045 00046 00048 // Math namespace 00049 00050 namespace Math 00051 { 00052 00054 // Helper functions 00055 00056 template<typename T> 00057 inline T Abs(const T& x) 00058 { 00059 return (x < 0 ? -x : x); 00060 } 00061 00062 template<typename T> 00063 inline T ATan(const T& x) 00064 { 00065 return atan(x); 00066 } 00067 00068 template<typename T> 00069 inline T Cos(const T& x) 00070 { 00071 return cos(x); 00072 } 00073 00074 template<typename T> 00075 inline T Exp(const T& x) 00076 { 00077 return exp(x); 00078 } 00079 00080 template<typename T> 00081 inline T Log(const T& x) 00082 { 00083 return T(log(static_cast<double>(x))); 00084 } 00085 00086 template<typename T> 00087 inline T Log2(const T& x) 00088 { 00089 return T(log(static_cast<double>(x))/log(2.)); 00090 } 00091 00092 template<typename T> 00093 inline T Pow(const T& x, const T& y) 00094 { 00095 return T(pow(x, y)); 00096 } 00097 00098 template<typename T> 00099 inline T Sin(const T& x) 00100 { 00101 return sin(x); 00102 } 00103 00104 template<typename T> 00105 inline T Sqrt(const T& x) 00106 { 00107 return T(sqrt(x)); 00108 } 00109 00110 template<typename T> 00111 inline T Tan(const T& x) 00112 { 00113 return tan(x); 00114 } 00115 00116 00118 // Template specializations 00119 00120 template<> 00121 inline float ATan(const float& x) 00122 { 00123 return atanf(x); 00124 } 00125 00126 template<> 00127 inline float Cos(const float& x) 00128 { 00129 return cosf(x); 00130 } 00131 00132 template<> 00133 inline float Exp(const float& x) 00134 { 00135 return expf(x); 00136 } 00137 00138 template<> 00139 inline float Log(const float& x) 00140 { 00141 return logf(x); 00142 } 00143 00144 template<> 00145 inline float Pow(const float& x, const float& y) 00146 { 00147 return powf(x, y); 00148 } 00149 00150 template<> 00151 inline float Sin(const float& x) 00152 { 00153 return sinf(x); 00154 } 00155 00156 template<> 00157 inline float Sqrt(const float& x) 00158 { 00159 return sqrtf(x); 00160 } 00161 00162 template<> 00163 inline float Tan(const float& x) 00164 { 00165 return tanf(x); 00166 } 00167 00168 } // namespace Math 00169 00170 #endif // Math_Helpers_h