Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

VLMath.h

Go to the documentation of this file.
00001 /*
00002     File:           VLMath.h
00003 
00004     Function:       Various math definitions for VL
00005                     
00006     Author(s):      Andrew Willmott
00007 
00008     Copyright:      (c) 1995-2000, Andrew Willmott
00009  */
00010 
00011 #ifndef __VL_MATH__
00012 #define __VL_MATH__
00013 
00014 #include <stdlib.h>
00015 
00016 // --- Inlines ----------------------------------------------------------------
00017 
00018 // additions to arithmetic functions
00019 
00020 #ifdef VL_HAS_IEEEFP
00021 #include <ieeefp.h>
00022 #define vl_is_finite(X) finite(X)
00023 #elif defined (__GNUC__) && defined(__USE_MISC)
00024 #define vl_is_finite(X) finite(X)
00025 #else
00026 #define vl_is_finite(X) (1)
00027 #endif
00028 
00029 inline Double vl_rand()
00030 { return(drand48()); }
00031 
00032 #ifndef __CMATH__
00033 // GNU's complex.h defines its own abs(double)
00034 #ifdef VL_HAS_ABSF
00035 inline Float abs(Float x)
00036 { return (fabsf(x)); }
00037 #endif
00038 inline Double abs(Double x)
00039 { return (fabs(x)); }
00040 #endif
00041 #ifdef VL_HAS_ABSF
00042 inline Float len(Float x)
00043 { return (fabsf(x)); }
00044 #endif
00045 inline Double len(Double x)
00046 { return (fabs(x)); }
00047 
00048 inline Float sqrlen(Float r)
00049 { return(sqr(r)); }
00050 inline Double sqrlen(Double r)
00051 { return(sqr(r)); }
00052 
00053 inline Float mix(Float a, Float b, Float s)
00054 { return((1.0 - s) * a + s * b); }
00055 inline Double mix(Double a, Double b, Double s)
00056 { return((1.0 - s) * a + s * b); }
00057 
00058 inline Double sign(Double d)
00059 {
00060     if (d < 0)
00061         return(-1.0);
00062     else
00063         return(1.0);
00064 }
00065 
00066 // useful routines
00067 
00068 inline Void SetReal(Float &a, Double b)
00069 { a = b; }
00070 inline Void SetReal(Double &a, Double b)
00071 { a = b; }
00072 
00073 inline Bool IsPowerOfTwo(Int a)
00074 { return((a & -a) == a); };
00075 
00076 template <class S, class T> inline Void ConvertVec(const S &u, T &v)
00077 {
00078     for (Int i = 0; i < u.Elts(); i++)
00079         v[i] = u[i];
00080 }
00081 
00082 template <class T> inline Void ConvertVec(const T &u, T &v)
00083 { v = u; }
00084 
00085 template <class S, class T> inline Void ConvertMat(const S &m, T &n)
00086 {
00087     for (Int i = 0; i < m.Rows(); i++)
00088         ConvertVec(m[i], n[i]);
00089 }
00090 
00091 template <class T> inline Void ConvertMat(const T &m, T &n)
00092 { n = m; }
00093 
00094 
00095 #endif

Generated at Sat Aug 5 00:16:50 2000 for Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000