PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/ilmbase-1.0.2/ImathLimits.h
00001 
00002 //
00003 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
00004 // Digital Ltd. LLC
00005 // 
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are
00010 // met:
00011 // *       Redistributions of source code must retain the above copyright
00012 // notice, this list of conditions and the following disclaimer.
00013 // *       Redistributions in binary form must reproduce the above
00014 // copyright notice, this list of conditions and the following disclaimer
00015 // in the documentation and/or other materials provided with the
00016 // distribution.
00017 // *       Neither the name of Industrial Light & Magic nor the names of
00018 // its contributors may be used to endorse or promote products derived
00019 // from this software without specific prior written permission. 
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00034 
00035 
00036 
00037 #ifndef INCLUDED_IMATHLIMITS_H
00038 #define INCLUDED_IMATHLIMITS_H
00039 
00040 //----------------------------------------------------------------
00041 //
00042 //      Limitations of the basic C++ numerical data types
00043 //
00044 //----------------------------------------------------------------
00045 
00046 #include <float.h>
00047 #include <limits.h>
00048 
00049 //------------------------------------------
00050 // In Windows, min and max are macros.  Yay.
00051 //------------------------------------------
00052 
00053 #if defined _WIN32 || defined _WIN64
00054     #ifdef min
00055         #undef min
00056     #endif
00057     #ifdef max
00058         #undef max
00059     #endif
00060 #endif
00061 
00062 namespace Imath {
00063 
00064 
00065 //-----------------------------------------------------------------
00066 //
00067 // Template class limits<T> returns information about the limits
00068 // of numerical data type T:
00069 //
00070 //      min()           largest possible negative value of type T
00071 //
00072 //      max()           largest possible positive value of type T
00073 //
00074 //      smallest()      smallest possible positive value of type T
00075 //                      (for float and double: smallest normalized
00076 //                      positive value)
00077 //
00078 //      epsilon()       smallest possible e of type T, for which
00079 //                      1 + e != 1
00080 //
00081 //      isIntegral()    returns true if T is an integral type
00082 //
00083 //      isSigned()      returns true if T is signed
00084 //
00085 // Class limits<T> is useful to implement template classes or
00086 // functions which depend on the limits of a numerical type
00087 // which is not known in advance; for example:
00088 //
00089 //      template <class T> max (T x[], int n)
00090 //      {
00091 //          T m = limits<T>::min();
00092 //
00093 //          for (int i = 0; i < n; i++)
00094 //              if (m < x[i])
00095 //                  m = x[i];
00096 //
00097 //          return m;
00098 //      }
00099 //
00100 // Class limits<T> has been implemented for the following types:
00101 //
00102 //      char, signed char, unsigned char
00103 //      short, unsigned short
00104 //      int, unsigned int
00105 //      long, unsigned long
00106 //      float
00107 //      double
00108 //      long double
00109 //
00110 // Class limits<T> has only static member functions, all of which
00111 // are implemented as inlines.  No objects of type limits<T> are
00112 // ever created.
00113 //
00114 //-----------------------------------------------------------------
00115 
00116 
00117 template <class T> struct limits
00118 {
00119     static T    min();
00120     static T    max();
00121     static T    smallest();
00122     static T    epsilon();
00123     static bool isIntegral();
00124     static bool isSigned();
00125 };
00126 
00127 
00128 //---------------
00129 // Implementation
00130 //---------------
00131 
00132 template <>
00133 struct limits <char>
00134 {
00135     static char                 min()           {return CHAR_MIN;}
00136     static char                 max()           {return CHAR_MAX;}
00137     static char                 smallest()      {return 1;}
00138     static char                 epsilon()       {return 1;}
00139     static bool                 isIntegral()    {return true;}
00140     static bool                 isSigned()      {return (char) ~0 < 0;}
00141 };
00142 
00143 template <>
00144 struct limits <signed char>
00145 {
00146     static signed char          min()           {return SCHAR_MIN;}
00147     static signed char          max()           {return SCHAR_MAX;}
00148     static signed char          smallest()      {return 1;}
00149     static signed char          epsilon()       {return 1;}
00150     static bool                 isIntegral()    {return true;}
00151     static bool                 isSigned()      {return true;}
00152 };
00153 
00154 template <>
00155 struct limits <unsigned char>
00156 {
00157     static unsigned char        min()           {return 0;}
00158     static unsigned char        max()           {return UCHAR_MAX;}
00159     static unsigned char        smallest()      {return 1;}
00160     static unsigned char        epsilon()       {return 1;}
00161     static bool                 isIntegral()    {return true;}
00162     static bool                 isSigned()      {return false;}
00163 };
00164 
00165 template <>
00166 struct limits <short>
00167 {
00168     static short                min()           {return SHRT_MIN;}
00169     static short                max()           {return SHRT_MAX;}
00170     static short                smallest()      {return 1;}
00171     static short                epsilon()       {return 1;}
00172     static bool                 isIntegral()    {return true;}
00173     static bool                 isSigned()      {return true;}
00174 };
00175 
00176 template <>
00177 struct limits <unsigned short>
00178 {
00179     static unsigned short       min()           {return 0;}
00180     static unsigned short       max()           {return USHRT_MAX;}
00181     static unsigned short       smallest()      {return 1;}
00182     static unsigned short       epsilon()       {return 1;}
00183     static bool                 isIntegral()    {return true;}
00184     static bool                 isSigned()      {return false;}
00185 };
00186 
00187 template <>
00188 struct limits <int>
00189 {
00190     static int                  min()           {return INT_MIN;}
00191     static int                  max()           {return INT_MAX;}
00192     static int                  smallest()      {return 1;}
00193     static int                  epsilon()       {return 1;}
00194     static bool                 isIntegral()    {return true;}
00195     static bool                 isSigned()      {return true;}
00196 };
00197 
00198 template <>
00199 struct limits <unsigned int>
00200 {
00201     static unsigned int         min()           {return 0;}
00202     static unsigned int         max()           {return UINT_MAX;}
00203     static unsigned int         smallest()      {return 1;}
00204     static unsigned int         epsilon()       {return 1;}
00205     static bool                 isIntegral()    {return true;}
00206     static bool                 isSigned()      {return false;}
00207 };
00208 
00209 template <>
00210 struct limits <long>
00211 {
00212     static long                 min()           {return LONG_MIN;}
00213     static long                 max()           {return LONG_MAX;}
00214     static long                 smallest()      {return 1;}
00215     static long                 epsilon()       {return 1;}
00216     static bool                 isIntegral()    {return true;}
00217     static bool                 isSigned()      {return true;}
00218 };
00219 
00220 template <>
00221 struct limits <unsigned long>
00222 {
00223     static unsigned long        min()           {return 0;}
00224     static unsigned long        max()           {return ULONG_MAX;}
00225     static unsigned long        smallest()      {return 1;}
00226     static unsigned long        epsilon()       {return 1;}
00227     static bool                 isIntegral()    {return true;}
00228     static bool                 isSigned()      {return false;}
00229 };
00230 
00231 template <>
00232 struct limits <float>
00233 {
00234     static float                min()           {return -FLT_MAX;}
00235     static float                max()           {return FLT_MAX;}
00236     static float                smallest()      {return FLT_MIN;}
00237     static float                epsilon()       {return FLT_EPSILON;}
00238     static bool                 isIntegral()    {return false;}
00239     static bool                 isSigned()      {return true;}
00240 };
00241 
00242 template <>
00243 struct limits <double>
00244 {
00245     static double               min()           {return -DBL_MAX;}
00246     static double               max()           {return DBL_MAX;}
00247     static double               smallest()      {return DBL_MIN;}
00248     static double               epsilon()       {return DBL_EPSILON;}
00249     static bool                 isIntegral()    {return false;}
00250     static bool                 isSigned()      {return true;}
00251 };
00252 
00253 template <>
00254 struct limits <long double>
00255 {
00256     static long double          min()           {return -LDBL_MAX;}
00257     static long double          max()           {return LDBL_MAX;}
00258     static long double          smallest()      {return LDBL_MIN;}
00259     static long double          epsilon()       {return LDBL_EPSILON;}
00260     static bool                 isIntegral()    {return false;}
00261     static bool                 isSigned()      {return true;}
00262 };
00263 
00264 
00265 } // namespace Imath
00266 
00267 #endif