core/vnl/vnl_numeric_traits.cxx
Go to the documentation of this file.
00001 // This is core/vnl/vnl_numeric_traits.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Andrew W. Fitzgibbon, Oxford RRG
00008 // Created: 12 Feb 98
00009 //
00010 //-----------------------------------------------------------------------------
00011 
00012 #include "vnl_numeric_traits.h"
00013 #include <vcl_complex.h>
00014 #include <vxl_config.h>
00015 
00016 static const long s16 = 0x7fffL;
00017 static const unsigned long u16 = 0xffffL;
00018 static const long s32 = 0x7fffffffL;
00019 static const unsigned long u32 = 0xffffffffL;
00020 #if VXL_HAS_INT_64 // need this arithmetic magic to avoid compiler errors
00021 static const vxl_uint_64 u64 = (vxl_uint_64)(-1);
00022 static const vxl_sint_64 s64 = u64/2;
00023 #else // dummy
00024 static const long s64 = 0L;
00025 static const unsigned long u64 = 0L;
00026 #endif
00027 
00028 #if !VCL_STATIC_CONST_INIT_INT_NO_DEFN
00029 const bool vnl_numeric_traits<bool>::zero VCL_STATIC_CONST_INIT_INT_DEFN(false);
00030 const char vnl_numeric_traits<char>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00031 const unsigned char vnl_numeric_traits<unsigned char>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00032 const signed char vnl_numeric_traits<signed char>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00033 const short vnl_numeric_traits<short>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00034 const unsigned short vnl_numeric_traits<unsigned short>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00035 const int vnl_numeric_traits<int>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00036 const unsigned int vnl_numeric_traits<unsigned int>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00037 const long vnl_numeric_traits<long>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00038 const unsigned long vnl_numeric_traits<unsigned long>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00039 #if VCL_HAS_LONG_LONG
00040 const long long vnl_numeric_traits<long long>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00041 const unsigned long long vnl_numeric_traits<unsigned long long>::zero VCL_STATIC_CONST_INIT_INT_DEFN(0);
00042 #endif
00043 #endif
00044 
00045 #if !VCL_STATIC_CONST_INIT_INT_NO_DEFN
00046 const bool vnl_numeric_traits<bool>::one VCL_STATIC_CONST_INIT_INT_DEFN(true);
00047 const char vnl_numeric_traits<char>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00048 const unsigned char vnl_numeric_traits<unsigned char>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00049 const signed char vnl_numeric_traits<signed char>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00050 const short vnl_numeric_traits<short>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00051 const unsigned short vnl_numeric_traits<unsigned short>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00052 const int vnl_numeric_traits<int>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00053 const unsigned int vnl_numeric_traits<unsigned int>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00054 const long vnl_numeric_traits<long>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00055 const unsigned long vnl_numeric_traits<unsigned long>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00056 #if VCL_HAS_LONG_LONG
00057 const long long vnl_numeric_traits<long long>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00058 const unsigned long long vnl_numeric_traits<unsigned long long>::one VCL_STATIC_CONST_INIT_INT_DEFN(1);
00059 #endif
00060 #endif
00061 
00062 #if !VCL_STATIC_CONST_INIT_INT_NO_DEFN
00063 const bool vnl_numeric_traits<bool>::maxval VCL_STATIC_CONST_INIT_INT_DEFN(true);
00064 const char vnl_numeric_traits<char>::maxval VCL_STATIC_CONST_INIT_INT_DEFN(char(255)<0?127:255);
00065 //  It is 127 when "char" is signed and 255 when "char" is unsigned.
00066 const unsigned char vnl_numeric_traits<unsigned char>::maxval VCL_STATIC_CONST_INIT_INT_DEFN(255);
00067 const signed char vnl_numeric_traits<signed char>::maxval VCL_STATIC_CONST_INIT_INT_DEFN(127);
00068 #endif
00069 
00070 const short vnl_numeric_traits<short>::maxval = s16;
00071 const unsigned short vnl_numeric_traits<unsigned short>::maxval = u16;
00072 const int vnl_numeric_traits<int>::maxval = sizeof(int)==4?s32:s16;
00073 const unsigned int vnl_numeric_traits<unsigned int>::maxval = sizeof(unsigned int)==4?u32:u16;
00074 const long vnl_numeric_traits<long>::maxval = sizeof(long)==8?s64:s32;
00075 const unsigned long vnl_numeric_traits<unsigned long>::maxval = sizeof(unsigned long)==8?u64:u32;
00076 #if VCL_HAS_LONG_LONG
00077 const long long vnl_numeric_traits<long long>::maxval = sizeof(long long)==8?s64:s32;
00078 const unsigned long long vnl_numeric_traits<unsigned long long>::maxval = sizeof(unsigned long long)==8?u64:u32;
00079 #endif
00080 
00081 #if !VCL_STATIC_CONST_INIT_FLOAT_NO_DEFN
00082 const float vnl_numeric_traits<float>::zero VCL_STATIC_CONST_INIT_FLOAT_DEFN(0.0F);
00083 const double vnl_numeric_traits<double>::zero VCL_STATIC_CONST_INIT_FLOAT_DEFN(0.0);
00084 const long double vnl_numeric_traits<long double>::zero VCL_STATIC_CONST_INIT_FLOAT_DEFN(0.0);
00085 
00086 const float vnl_numeric_traits<float>::one VCL_STATIC_CONST_INIT_FLOAT_DEFN(1.0F);
00087 const double vnl_numeric_traits<double>::one VCL_STATIC_CONST_INIT_FLOAT_DEFN(1.0);
00088 const long double vnl_numeric_traits<long double>::one VCL_STATIC_CONST_INIT_FLOAT_DEFN(1.0);
00089 
00090 const float vnl_numeric_traits<float>::maxval VCL_STATIC_CONST_INIT_FLOAT_DEFN(3.40282346638528860e+38F);
00091 const double vnl_numeric_traits<double>::maxval VCL_STATIC_CONST_INIT_FLOAT_DEFN(1.7976931348623157E+308);
00092 const long double vnl_numeric_traits<long double>::maxval VCL_STATIC_CONST_INIT_FLOAT_DEFN(1.7976931348623157E+308);
00093 #endif
00094 
00095 // Must use constructor-call syntax for initialization of complex
00096 // specializations for Borland compiler.
00097 const vcl_complex<float> vnl_numeric_traits<vcl_complex<float> >::zero(0.0f);
00098 const vcl_complex<double> vnl_numeric_traits<vcl_complex<double> >::zero(0.0);
00099 const vcl_complex<long double> vnl_numeric_traits<vcl_complex<long double> >::zero(0.0);
00100 
00101 const vcl_complex<float> vnl_numeric_traits<vcl_complex<float> >::one(1.0f);
00102 const vcl_complex<double> vnl_numeric_traits<vcl_complex<double> >::one(1.0);
00103 const vcl_complex<long double> vnl_numeric_traits<vcl_complex<long double> >::one(1.0);
00104 
00105 // Unknown, so undefined. Will cause link errors if someone refers to it.
00106 //const vcl_complex<float> vnl_numeric_traits<vcl_complex<float> >::maxval;
00107 //const vcl_complex<double> vnl_numeric_traits<vcl_complex<double> >::maxval;
00108 //const vcl_complex<long double> vnl_numeric_traits<vcl_complex<long double> >::maxval;
00109 
00110 //--------------------------------------------------------------------------------