00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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
00115
00116
00117
00118
00119
00120
00121
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
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 }
00161
00162 #endif // !NTG_REAL_BUILTIN_PROPERTIES_HH