00001 /*! \file scppnt_math.h 00002 \brief Definitions of some scalar math functions. 00003 00004 Defines templated scalar functions abs() min(), max(), and sign() required 00005 by several matrix algorithms. 00006 00007 */ 00008 00009 /* 00010 00011 Simple C++ Numerical Toolkit (SCPPNT) 00012 http://www.smallwaters.com/software/cpp/scppnt.html 00013 This release updates original work contributed by 00014 Brad Hanson (http://www.b-a-h.com/) in 2001. 00015 00016 */ 00017 00018 // Modified version of file tntmath.h from: 00019 /* 00020 * 00021 * Template Numerical Toolkit (TNT): Linear Algebra Module 00022 * 00023 * Mathematical and Computational Sciences Division 00024 * National Institute of Technology, 00025 * Gaithersburg, MD USA 00026 * 00027 * 00028 * This software was developed at the National Institute of Standards and 00029 * Technology (NIST) by employees of the Federal Government in the course 00030 * of their official duties. Pursuant to title 17 Section 105 of the 00031 * United States Code, this software is not subject to copyright protection 00032 * and is in the public domain. The Template Numerical Toolkit (TNT) is 00033 * an experimental system. NIST assumes no responsibility whatsoever for 00034 * its use by other parties, and makes no guarantees, expressed or implied, 00035 * about its quality, reliability, or any other characteristic. 00036 * 00037 * BETA VERSION INCOMPLETE AND SUBJECT TO CHANGE 00038 * see http://math.nist.gov/tnt for latest updates. 00039 * 00040 */ 00041 00042 #ifndef SCPPNT_MATH_H 00043 #define SCPPNT_MATH_H 00044 00045 namespace SCPPNT 00046 { 00047 00048 //! Returns absolute value of argument 00049 template<class T> inline T abs(T x) 00050 { 00051 return (x > 0 ? x : -x); 00052 } 00053 00054 //! Returns minimum of two scalars 00055 template<class T> inline T min(T a, T b) 00056 { 00057 return (a < b ? a : b); 00058 } 00059 00060 //! Returns maximum of two scalars 00061 template<class T> inline T max(T a, T b) 00062 { 00063 return (a > b ? a : b); 00064 } 00065 00066 //! Returns 1 if argument is positive, otherwise returns -1 00067 template<class T> inline T sign(T a) 00068 { 00069 return (a > 0 ? 1.0 : -1.0); 00070 } 00071 00072 } /* namespace SCPPNT */ 00073 00074 #endif /* SCPPNT_MATH_H */ 00075