builtin_properties.hh

00001 // Copyright (C) 2001, 2002, 2003  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef NTG_REAL_BUILTIN_PROPERTIES_HH
00029 # define NTG_REAL_BUILTIN_PROPERTIES_HH
00030 
00031 # include <mlc/math.hh>
00032 
00033 # include <limits.h>
00034 # include <float.h>
00035 
00036 namespace ntg
00037 {
00038   
00039   /*-------------------.
00040   | C_for_ntg integers |
00041   `-------------------*/
00042 
00043   template<unsigned nbits>
00044   struct C_for_int_u
00045   {
00046     enum {
00047       mbits = mlc::pow2sup<nbits>::value
00048     };
00049     typedef typename C_for_int_u<mbits>::type type;
00050     static type max() {
00051       return type((type(1) << nbits) - type(1));
00052     }
00053   };
00054 
00055   template<unsigned nbits>
00056   struct C_for_int_s
00057   {
00058     enum { mbits = mlc::pow2sup<nbits>::value };
00059     typedef typename C_for_int_s<mbits>::type type;
00060     static type min() {
00061       return type(- max() - type(1));
00062     }
00063     static type max() {
00064       return type((type(1) << (nbits-1)) - type(1));
00065     }
00066   };
00067 
00068   template<>
00069   struct C_for_int_u<8>
00070   {
00071     typedef unsigned char type;
00072     static type max() { return UCHAR_MAX; }
00073   };
00074 
00075 
00076   template<>
00077   struct C_for_int_s<8>
00078   {
00079     typedef signed char type;
00080     static type min() { return CHAR_MIN; }
00081     static type max() { return CHAR_MAX; }
00082   };
00083 
00084   template<>
00085   struct C_for_int_u<16>
00086   {
00087     typedef unsigned short type;
00088     static type max() { return USHRT_MAX; }
00089   };
00090 
00091   template<>
00092   struct C_for_int_s<16>
00093   {
00094     typedef signed short type;
00095     static type min() { return SHRT_MIN; }
00096     static type max() { return SHRT_MAX; }
00097   };
00098 
00099   template<>
00100   struct C_for_int_u<32>
00101   {
00102     typedef unsigned int type;
00103     static type max() { return UINT_MAX; }
00104   };
00105 
00106   template<>
00107   struct C_for_int_s<32>
00108   {
00109     typedef signed int type;
00110     static type min() { return INT_MIN; }
00111     static type max() { return INT_MAX; }
00112   };
00113 
00114   // TODO: add 64 bits integers support is they are available.
00115 
00116   /*----------------.
00117   | C_for_ntg float |
00118   `----------------*/
00119 
00120   // FIXME: this code is not used anywhere, maybe it should be
00121   // removed.
00122 
00123   struct C_for_float_s
00124   {
00125     typedef float type;
00126     static type min() { return FLT_MIN; }
00127     static type max() { return FLT_MAX; }
00128   };
00129 
00130   struct C_for_float_d
00131   {
00132     typedef double type;
00133     static type min() { return DBL_MIN; }
00134     static type max() { return DBL_MAX; }
00135   };
00136 
00137   // IEEE : Take a look at epsilon for some conditional (FIXME)
00138 
00139   //      FLT_RADIX                             2
00140   //      FLT_MANT_DIG                         24
00141   //      FLT_DIG                               6
00142   //      FLT_MIN_EXP                        -125
00143   //      FLT_MIN_10_EXP                      -37
00144   //      FLT_MAX_EXP                         128
00145   //      FLT_MAX_10_EXP                      +38
00146   //      FLT_MIN                 1.17549435E-38F
00147   //      FLT_MAX                 3.40282347E+38F
00148   //      FLT_EPSILON             1.19209290E-07F
00149 
00150   //      DBL_MANT_DIG                         53
00151   //      DBL_DIG                              15
00152   //      DBL_MIN_EXP                       -1021
00153   //      DBL_MIN_10_EXP                     -307
00154   //      DBL_MAX_EXP                        1024
00155   //      DBL_MAX_10_EXP                      308
00156   //      DBL_MAX         1.7976931348623157E+308
00157   //      DBL_MIN         2.2250738585072014E-308
00158   //      DBL_EPSILON     2.2204460492503131E-016
00159 
00160 } // end of ntg.
00161 
00162 #endif // !NTG_REAL_BUILTIN_PROPERTIES_HH

Generated on Thu Apr 15 20:13:07 2004 for Olena by doxygen 1.3.6-20040222