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