library of assembled shared sources

http://lass.cocamware.com

num_traits.cpp

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 #include "num_common.h"
00046 
00047 #include "num_traits.h"
00048 #include "interval.h"
00049 #include <climits>
00050 #include <cfloat>
00051 
00052 #ifdef LASS_CHAR_IS_SIGNED
00053 #   pragma LASS_NOTE("char is configured as signed char")
00054 #endif
00055 
00056 // http://pi.lacim.uqam.ca/eng/table_en.html
00057 #define LASS_NUM_PI         3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
00058 #define LASS_NUM_E          2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
00059 #define LASS_NUM_SQRT_2     1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572
00060 #define LASS_NUM_SQRT_PI    1.772453850905516027298167483341145
00061 
00062 namespace lass
00063 {
00064 namespace num
00065 {
00066 
00067 /***********************************************************************
00068 * float num trait
00069 */
00070 
00071 /*  got rid of the template<> because VS2003 didn't like it although but we did
00072 *   and at first and second glance the standard also likes it [TDM]
00073 */
00074 template <> struct LASS_DLL NumTraits<float>;
00075 const size_t   NumTraits<float>::memorySize = sizeof(float);
00076 const size_t   NumTraits<float>::mantisseSize = std::numeric_limits<float>::digits;         
00077 const float NumTraits<float>::one = 1.f;
00078 const float NumTraits<float>::zero = 0.f;
00079 const float NumTraits<float>::qNaN = std::numeric_limits<float>::quiet_NaN();
00080 const float NumTraits<float>::sNaN = std::numeric_limits<float>::signaling_NaN();
00081 const float NumTraits<float>::infinity = std::numeric_limits<float>::infinity();
00082 const float NumTraits<float>::epsilon = FLT_EPSILON;
00083 const float NumTraits<float>::min = -FLT_MAX;
00084 const float NumTraits<float>::max = FLT_MAX;
00085 const float NumTraits<float>::minStrictPositive = FLT_MIN;
00086 const float NumTraits<float>::pi = float(LASS_NUM_PI);
00087 const float NumTraits<float>::e = float(LASS_NUM_E);
00088 const float NumTraits<float>::sqrt2 = float(LASS_NUM_SQRT_2);
00089 const float NumTraits<float>::sqrtPi = float(LASS_NUM_SQRT_PI);
00090 
00091 // complex specialisation
00092 template <> struct LASS_DLL NumTraits< std::complex<float> >;
00093 const size_t   NumTraits<std::complex<float> >::memorySize = sizeof(std::complex<float>);
00094 const std::complex<float>   NumTraits<std::complex<float> >::one = std::complex<float>(1.f, 0.f);
00095 const std::complex<float>   NumTraits<std::complex<float> >::zero = std::complex<float>(0.f, 0.f);
00096 const std::complex<float>   NumTraits<std::complex<float> >::pi = float(LASS_NUM_PI);
00097 const std::complex<float>   NumTraits<std::complex<float> >::e = float(LASS_NUM_E);
00098 const std::complex<float>   NumTraits<std::complex<float> >::sqrt2 = float(LASS_NUM_SQRT_2);
00099 const std::complex<float>   NumTraits<std::complex<float> >::sqrtPi = float(LASS_NUM_SQRT_PI);
00100 
00101 /***********************************************************************
00102 * double num trait
00103 */
00104 template <> struct LASS_DLL NumTraits<double>;
00105 const size_t   NumTraits<double>::memorySize = sizeof(double);
00106 const size_t   NumTraits<double>::mantisseSize = std::numeric_limits<double>::digits;
00107 const double    NumTraits<double>::one = 1.0;
00108 const double NumTraits<double>::zero= 0.0;
00109 const double    NumTraits<double>::qNaN = std::numeric_limits<double>::quiet_NaN();
00110 const double    NumTraits<double>::sNaN = std::numeric_limits<double>::signaling_NaN();
00111 const double NumTraits<double>::infinity = std::numeric_limits<double>::infinity();
00112 const double NumTraits<double>::epsilon = DBL_EPSILON;
00113 const double    NumTraits<double>::min = -DBL_MAX;
00114 const double    NumTraits<double>::max = DBL_MAX;
00115 const double    NumTraits<double>::minStrictPositive = DBL_MIN;
00116 const double    NumTraits<double>::pi = LASS_NUM_PI;
00117 const double    NumTraits<double>::e = LASS_NUM_E;
00118 const double    NumTraits<double>::sqrt2 = LASS_NUM_SQRT_2;
00119 const double    NumTraits<double>::sqrtPi = LASS_NUM_SQRT_PI;
00120 
00121 // complex specialisation
00122 template <> struct LASS_DLL NumTraits< std::complex<double> >;
00123 const size_t   NumTraits<std::complex<double> >::memorySize = sizeof(std::complex<double>);
00124 const std::complex<double>  NumTraits<std::complex<double> >::one = std::complex<double>(1.0, 0.0);
00125 const std::complex<double>  NumTraits<std::complex<double> >::zero = std::complex<double>(0.0, 0.0);
00126 const std::complex<double>  NumTraits<std::complex<double> >::pi = LASS_NUM_PI;
00127 const std::complex<double>  NumTraits<std::complex<double> >::e = LASS_NUM_E;
00128 const std::complex<double>  NumTraits<std::complex<double> >::sqrt2 = LASS_NUM_SQRT_2;
00129 const std::complex<double>  NumTraits<std::complex<double> >::sqrtPi = LASS_NUM_SQRT_PI;
00130 
00131 /***********************************************************************
00132 * long double num trait
00133 */
00134 template <> struct LASS_DLL NumTraits<long double>;
00135 const size_t   NumTraits<long double>::memorySize = sizeof(long double);
00136 const size_t   NumTraits<long double>::mantisseSize = std::numeric_limits<long double>::digits;
00137 const long double    NumTraits<long double>::one = 1.0;
00138 const long double NumTraits<long double>::zero= 0.0;
00139 const long double    NumTraits<long double>::qNaN = std::numeric_limits<long double>::quiet_NaN();
00140 const long double    NumTraits<long double>::sNaN = std::numeric_limits<long double>::signaling_NaN();
00141 const long double NumTraits<long double>::infinity = std::numeric_limits<long double>::infinity();
00142 const long double NumTraits<long double>::epsilon = LDBL_EPSILON;
00143 const long double    NumTraits<long double>::min = -LDBL_MAX;
00144 const long double    NumTraits<long double>::max = LDBL_MAX;
00145 const long double    NumTraits<long double>::minStrictPositive = LDBL_MIN;
00146 const long double    NumTraits<long double>::pi = LASS_NUM_PI;
00147 const long double    NumTraits<long double>::e = LASS_NUM_E;
00148 const long double    NumTraits<long double>::sqrt2 = LASS_NUM_SQRT_2;
00149 const long double    NumTraits<long double>::sqrtPi = LASS_NUM_SQRT_PI;
00150 
00151 // complex specialisation
00152 template <> struct LASS_DLL NumTraits< std::complex<long double> >;
00153 const size_t   NumTraits<std::complex<long double> >::memorySize = sizeof(std::complex<long double>);
00154 const std::complex<long double>  NumTraits<std::complex<long double> >::one = std::complex<long double>(1.0, 0.0);
00155 const std::complex<long double>  NumTraits<std::complex<long double> >::zero = std::complex<long double>(0.0, 0.0);
00156 const std::complex<long double>  NumTraits<std::complex<long double> >::pi = LASS_NUM_PI;
00157 const std::complex<long double>  NumTraits<std::complex<long double> >::e = LASS_NUM_E;
00158 const std::complex<long double>  NumTraits<std::complex<long double> >::sqrt2 = LASS_NUM_SQRT_2;
00159 const std::complex<long double>  NumTraits<std::complex<long double> >::sqrtPi = LASS_NUM_SQRT_PI;
00160 
00161 /***********************************************************************
00162 * unsigned/signed char/short/int/long num trait
00163 */
00164 
00165 /** code generating macro for integral types */
00166 #define LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( t_type, v_min, v_max ) \
00167 template <> struct LASS_DLL NumTraits<t_type>;\
00168 const size_t   NumTraits<t_type>::memorySize = sizeof(t_type);\
00169 const size_t   NumTraits<t_type>::mantisseSize = 0;\
00170 const t_type NumTraits<t_type>::one = 1;\
00171 const t_type NumTraits<t_type>::zero= 0;\
00172 const t_type NumTraits<t_type>::epsilon = 1;\
00173 const t_type NumTraits<t_type>::min = v_min;\
00174 const t_type NumTraits<t_type>::max = v_max;\
00175 const t_type NumTraits<t_type>::minStrictPositive = 1;\
00176 
00177 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( char, CHAR_MIN , CHAR_MAX )
00178 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( unsigned char, 0 , UCHAR_MAX)
00179 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( signed char, SCHAR_MIN , SCHAR_MAX )
00180 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( unsigned short, 0 , USHRT_MAX)
00181 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( signed short, SHRT_MIN , SHRT_MAX )
00182 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( unsigned int, 0 , UINT_MAX )
00183 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( signed int, INT_MIN , INT_MAX )
00184 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( unsigned long, 0 , ULONG_MAX )
00185 LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( signed long, LONG_MIN , LONG_MAX )
00186 #if LASS_PLATFORM_TYPE == LASS_PLATFORM_TYPE_WIN32
00187     LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( unsigned __int64, 0 , ULLONG_MAX )
00188     LASS_NUM_TRAITS_INTEGRAL_TEMPLATE_SPEC( signed __int64, LLONG_MIN, LLONG_MAX )
00189 #endif
00190 
00191 }
00192 }

Generated on Mon Nov 10 14:20:31 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo