Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Utils.h
00001 /* 00002 File: Utils.h 00003 00004 Function: Various math definitions for VL 00005 00006 Author(s): Andrew Willmott 00007 00008 Copyright: (c) 1995-2001, Andrew Willmott 00009 */ 00010 00011 #ifndef __VL_MATH__ 00012 #define __VL_MATH__ 00013 00014 //#include <cstdlib> 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 #ifdef VL_HAS_DRAND 00030 inline Double vl_rand() 00031 { return(drand48()); } 00032 #else 00033 #ifndef RAND_MAX 00034 // we're on something totally sucky, like SunOS 00035 #define RAND_MAX (Double(1 << 30) * 4.0 - 1.0) 00036 #endif 00037 inline Double vl_rand() 00038 { return(rand() / (RAND_MAX + 1.0)); } 00039 #endif 00040 00041 #ifndef __CMATH__ 00042 // GNU's complex.h defines its own abs(double) 00043 #ifdef VL_HAS_ABSF 00044 inline Float abs(Float x) 00045 { return (fabsf(x)); } 00046 #endif 00047 // jmc ......... 7/19 00048 //inline Double abs(Double x) 00049 //{ return (fabs(x)); } 00050 #endif 00051 #ifdef VL_HAS_ABSF 00052 inline Float len(Float x) 00053 { return (fabsf(x)); } 00054 #endif 00055 inline Double len(Double x) 00056 { return (fabs(x)); } 00057 00058 inline Float sqrlen(Float r) 00059 { return(sqr(r)); } 00060 inline Double sqrlen(Double r) 00061 { return(sqr(r)); } 00062 00063 inline Float mix(Float a, Float b, Float s) 00064 { return((1.0f - s) * a + s * b); } 00065 inline Double mix(Double a, Double b, Double s) 00066 { return((1.0 - s) * a + s * b); } 00067 00068 inline Double sign(Double d) 00069 { 00070 if (d < 0) 00071 return(-1.0); 00072 else 00073 return(1.0); 00074 } 00075 00076 // useful routines 00077 00078 inline Bool IsPowerOfTwo(Int a) 00079 { return((a & -a) == a); }; 00080 00081 inline Void SetReal(Float &a, Double b) 00082 { a = Float(b); } 00083 inline Void SetReal(Double &a, Double b) 00084 { a = b; } 00085 00086 #endif
Generated on Wed Jul 13 2022 19:31:42 by
1.7.2