lim.h

Go to the documentation of this file.
00001 #ifndef __lim_h__
00002 #define __lim_h__
00003 
00004 #include <limits.h>
00005 #include <float.h>
00006 
00007 #include <exception>
00008 
00009 /** A small set of numeric limits routines, since gcc prior to 3.x doesn't
00010  * have numeric_limits */
00011 
00012 // ---------------------------------------------------------------------------
00013 
00014 template<typename T>
00015 static T max_limit()
00016 {
00017         T tmp = 0;
00018         static T max = 0;
00019         static bool found = false;
00020 
00021         if (found)
00022                 return(max);
00023         
00024         tmp = 1;
00025         max = 0;
00026         while (tmp > max) {
00027                 max = tmp;
00028                 tmp = (tmp * 2) + 1;
00029         }
00030         found = true;
00031         return(max);
00032 }
00033 
00034 template<typename T>
00035 static T min_limit()
00036 {
00037         T tmp = 0;
00038         static T min = 0;
00039         static bool found = false;
00040 
00041         if (found)
00042                 return(min);
00043         
00044         tmp = -1;
00045         min = 0;
00046         while (tmp < min) {
00047                 min = tmp;
00048                 tmp = (tmp * 2) - 1;
00049         }
00050         
00051         tmp = - max_limit<T>() - 1;
00052         if (tmp < min) {
00053                 min = tmp;
00054         }
00055 
00056         found = true;
00057         return(min);
00058 }
00059 
00060 template<>
00061 static float max_limit<float>()
00062 {
00063         return(FLT_MAX);
00064 }
00065 
00066 template<>
00067 static float min_limit<float>()
00068 {
00069         return(FLT_MIN);
00070 }
00071 
00072 template<>
00073 static double max_limit<double>()
00074 {
00075         return(DBL_MAX);
00076 }
00077 
00078 template<>
00079 static double min_limit<double>()
00080 {
00081         return(DBL_MIN);
00082 }
00083 
00084 // ---------------------------------------------------------------------------
00085 
00086 #endif

Generated on Mon Jul 12 12:02:44 2004 for rvm by doxygen 1.3.6