Blender V2.61 - r43446

tntmath.h

Go to the documentation of this file.
00001 
00004 /*
00005 
00006 *
00007 * Template Numerical Toolkit (TNT): Linear Algebra Module
00008 *
00009 * Mathematical and Computational Sciences Division
00010 * National Institute of Technology,
00011 * Gaithersburg, MD USA
00012 *
00013 *
00014 * This software was developed at the National Institute of Standards and
00015 * Technology (NIST) by employees of the Federal Government in the course
00016 * of their official duties. Pursuant to title 17 Section 105 of the
00017 * United States Code, this software is not subject to copyright protection
00018 * and is in the public domain.  The Template Numerical Toolkit (TNT) is
00019 * an experimental system.  NIST assumes no responsibility whatsoever for
00020 * its use by other parties, and makes no guarantees, expressed or implied,
00021 * about its quality, reliability, or any other characteristic.
00022 *
00023 * BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE
00024 * see http://math.nist.gov/tnt for latest updates.
00025 *
00026 */
00027 
00028 
00029 
00030 // Header file for scalar math functions
00031 
00032 #ifndef TNTMATH_H
00033 #define TNTMATH_H
00034 
00035 // conventional functions required by several matrix algorithms
00036 
00037 #ifdef _WIN32
00038 #define hypot _hypot
00039 #endif
00040 
00041 namespace TNT 
00042 {
00043 
00044 struct TNTException {
00045         int i;
00046 };
00047 
00048 
00049 inline double abs(double t)
00050 {
00051     return ( t > 0 ? t : -t);
00052 }
00053 
00054 inline double min(double a, double b)
00055 {
00056     return (a < b ? a : b);
00057 }
00058 
00059 inline double max(double a, double b)
00060 {
00061     return (a > b ? a : b);
00062 }
00063 
00064 inline float abs(float t)
00065 {
00066     return ( t > 0 ? t : -t);
00067 }
00068 
00069 inline float min(float a, float b)
00070 {
00071     return (a < b ? a : b);
00072 }
00073 
00074 inline int min(int a, int b)
00075 {
00076     return (a < b ? a : b);
00077 }
00078 
00079 inline int max(int a, int b)
00080 {
00081     return (a > b ? a : b);
00082 }
00083 
00084 inline float max(float a, float b)
00085 {
00086     return (a > b ? a : b);
00087 }
00088 
00089 inline double sign(double a)
00090 {
00091     return (a > 0 ? 1.0 : -1.0);
00092 }
00093 
00094 inline double sign(double a,double b) {
00095     return (b >= 0.0 ? TNT::abs(a) : -TNT::abs(a));
00096 }
00097 
00098 inline float sign(float a,float b) {
00099     return (b >= 0.0f ? TNT::abs(a) : -TNT::abs(a));
00100 }
00101 
00102 inline float sign(float a)
00103 {
00104     return (a > 0.0 ? 1.0f : -1.0f);
00105 }
00106 
00107 inline float pythag(float a, float b)
00108 {
00109     float absa,absb;
00110     absa = abs(a);
00111     absb = abs(b);
00112 
00113     if (absa > absb) {
00114         float sqr = absb/absa;
00115         sqr *= sqr;
00116         return absa * float(sqrt(1 + sqr));
00117     } else {
00118         if (absb > float(0)) {
00119             float sqr = absa/absb;
00120             sqr *= sqr;
00121             return absb * float(sqrt(1 + sqr));
00122         } else {
00123             return float(0);
00124         }
00125     }
00126 }
00127 
00128 inline double pythag(double a, double b)
00129 {
00130     double absa,absb;
00131     absa = abs(a);
00132     absb = abs(b);
00133 
00134     if (absa > absb) {
00135         double sqr = absb/absa;
00136         sqr *= sqr;
00137         return absa * double(sqrt(1 + sqr));
00138     } else {
00139 
00140         if (absb > double(0)) { 
00141             double sqr = absa/absb;
00142             sqr *= sqr;
00143             return absb * double(sqrt(1 + sqr));
00144         } else {
00145             return double(0);
00146         }
00147     }
00148 }
00149 
00150 
00151 } /* namespace TNT */
00152 
00153 #endif /* TNTMATH_H */
00154