00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _GAN_MISC_DEFS_H
00030 #define _GAN_MISC_DEFS_H
00031
00032 #include <stdlib.h>
00033 #include <stddef.h>
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <float.h>
00037 #include <limits.h>
00038 #include <assert.h>
00039 #include <gandalf/config.h>
00040
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044
00055
00056
00057
00058 #ifdef HAVE_SCSL
00059 #ifdef HAVE_LAPACK
00060 #error Conflicting versions of LAPACK on SGI
00061 #endif
00062
00063 #define HAVE_LAPACK 1
00064 #endif
00065
00067 typedef enum
00068 {
00070 GAN_FALSE=0,
00071
00073 GAN_TRUE=1
00074 } Gan_Bool;
00075
00076
00077 #ifdef NDEBUG
00078 #define gan_eval(x) ((void) 0)
00079 #else
00080 #define gan_eval(x) (x)
00081 #endif
00082
00083
00084
00085
00087 typedef enum
00088 {
00089 GAN_CHAR,
00090 GAN_UCHAR,
00091 GAN_SHORT,
00092 GAN_USHORT,
00093 GAN_INT,
00094 GAN_UINT,
00095 GAN_LONG,
00096 GAN_ULONG,
00097 GAN_FLOAT,
00098 GAN_DOUBLE,
00099 GAN_LONGDOUBLE,
00100 GAN_STRING,
00101 GAN_BOOL,
00102 GAN_POINTER,
00103 #if (SIZEOF_LONG_LONG != 0)
00104 GAN_LONGLONG,
00105 #endif
00106 GAN_UNDEFINED_TYPE
00107 } Gan_Type;
00108
00110 extern const size_t gan_type_sizes[];
00111
00112
00113
00114
00115
00116
00117 #if (SIZEOF_CHAR == 1)
00118 #define GAN_CHAR_MAXD 127.0
00119 #define GAN_CHAR_MAXF 127.0F
00120 #define GAN_UCHAR_MAXD 255.0
00121 #define GAN_UCHAR_MAXF 255.0F
00122 #endif
00123
00124 #if (SIZEOF_SHORT == 2)
00125 #define GAN_SHRT_MAXD 32767.0
00126 #define GAN_SHRT_MAXF 32767.0F
00127 #define GAN_USHRT_MAXD 65535.0
00128 #define GAN_USHRT_MAXF 65535.0F
00129 #elif (SIZEOF_SHORT == 4)
00130 #define GAN_SHRT_MAXD 2147483647.0
00131 #define GAN_SHRT_MAXF 2147483647.0F
00132 #define GAN_USHRT_MAXD 4294967295.0
00133 #define GAN_USHRT_MAXF 4294967295.0F
00134 #elif (SIZEOF_SHORT == 8)
00135 #define GAN_SHRT_MAXD 9.2233720368547758e18
00136 #define GAN_SHRT_MAXF 9.2233720368547758e18F
00137 #define GAN_USHRT_MAXD 1.8446744073709552e19
00138 #define GAN_USHRT_MAXF 1.8446744073709552e19F
00139 #endif
00140
00141 #if (SIZEOF_INT == 2)
00142 #define GAN_INT_MAXD 32767.0
00143 #define GAN_INT_MAXF 32767.0F
00144 #define GAN_UINT_MAXD 65535.0
00145 #define GAN_UINT_MAXF 65535.0F
00146 #elif (SIZEOF_INT == 4)
00147 #define GAN_INT_MAXD 2147483647.0
00148 #define GAN_INT_MAXF 2147483647.0F
00149 #define GAN_UINT_MAXD 4294967295.0
00150 #define GAN_UINT_MAXF 4294967295.0F
00151 #elif (SIZEOF_INT == 8)
00152 #define GAN_INT_MAXD 9.2233720368547758e18
00153 #define GAN_INT_MAXF 9.2233720368547758e18F
00154 #define GAN_UINT_MAXD 1.8446744073709552e19
00155 #define GAN_UINT_MAXF 1.8446744073709552e19F
00156 #endif
00157
00158 #if (SIZEOF_LONG == 4)
00159 #define GAN_ULONG_MAXD 4294967295.0
00160 #define GAN_ULONG_MAXF 4294967295.0F
00161 #elif (SIZEOF_LONG == 8)
00162 #define GAN_LONG_MAXD 9.2233720368547758e18
00163 #define GAN_LONG_MAXF 9.2233720368547758e18F
00164 #define GAN_ULONG_MAXD 1.8446744073709552e19
00165 #define GAN_ULONG_MAXF 1.8446744073709552e19F
00166 #endif
00167
00168
00169 #if (SIZEOF_CHAR == 1)
00170 typedef char gan_int8;
00171 typedef unsigned char gan_uint8;
00172 #define GAN_INT8 GAN_CHAR
00173 #define GAN_UINT8 GAN_UCHAR
00174 #define GAN_INT8_MIN CHAR_MIN
00175 #define GAN_INT8_MAX CHAR_MAX
00176 #define GAN_UINT8_MAX UCHAR_MAX
00177 #define GAN_UINT8_MAXD GAN_UCHAR_MAXD
00178 #define GAN_UINT8_MAXF GAN_UCHAR_MAXF
00179 #endif
00180
00181
00182 #if (SIZEOF_SHORT == 2)
00183 typedef short gan_int16;
00184 typedef unsigned short gan_uint16;
00185 #define GAN_INT16 GAN_SHORT
00186 #define GAN_UINT16 GAN_USHORT
00187 #define GAN_INT16_MIN SHRT_MIN
00188 #define GAN_INT16_MAX SHRT_MAX
00189 #define GAN_UINT16_MAX USHRT_MAX
00190 #define GAN_UINT16_MAXD GAN_USHRT_MAXD
00191 #define GAN_UINT16_MAXF GAN_USHRT_MAXF
00192 #elif (SIZEOF_INT == 2)
00193 typedef int gan_int16;
00194 typedef unsigned int gan_uint16;
00195 #define GAN_INT16 GAN_INT
00196 #define GAN_UINT16 GAN_UINT
00197 #define GAN_INT16_MIN INT_MIN
00198 #define GAN_INT16_MAX INT_MAX
00199 #define GAN_UINT16_MAX UINT_MAX
00200 #define GAN_UINT16_MAXD GAN_UINT_MAXD
00201 #define GAN_UINT16_MAXF GAN_UINT_MAXF
00202 #endif
00203
00204
00205 #if (SIZEOF_INT == 4)
00206 typedef int gan_int32;
00207 typedef unsigned int gan_uint32;
00208 #define GAN_INT32 GAN_INT
00209 #define GAN_UINT32 GAN_UINT
00210 #define GAN_INT32_MIN INT_MIN
00211 #define GAN_INT32_MAX INT_MAX
00212 #define GAN_UINT32_MAX UINT_MAX
00213 #define GAN_UINT32_MAXD GAN_UINT_MAXD
00214 #define GAN_UINT32_MAXF GAN_UINT_MAXF
00215 #elif (SIZEOF_LONG == 4)
00216 typedef long gan_int32;
00217 typedef unsigned long gan_uint32;
00218 #define GAN_INT32 GAN_LONG
00219 #define GAN_UINT32 GAN_ULONG
00220 #define GAN_INT32_MIN LONG_MIN
00221 #define GAN_INT32_MAX LONG_MAX
00222 #define GAN_UINT32_MAX ULONG_MAX
00223 #define GAN_UINT32_MAXD GAN_ULONG_MAXD
00224 #define GAN_UINT32_MAXF GAN_ULONG_MAXF
00225 #endif
00226
00227
00228 #if (SIZEOF_INT == 8)
00229 typedef int gan_int64;
00230 typedef unsigned int gan_uint64;
00231 #define GAN_INT64 GAN_INT
00232 #define GAN_UINT64 GAN_UINT
00233 #define GAN_INT64_MIN INT_MIN
00234 #define GAN_INT64_MAX INT_MAX
00235 #define GAN_UINT64_MAX UINT_MAX
00236 #define GAN_UINT64_MAXD GAN_UINT_MAXD
00237 #define GAN_UINT64_MAXF GAN_UINT_MAXF
00238 #elif (SIZEOF_LONG == 8)
00239 typedef long gan_int64;
00240 typedef unsigned long gan_uint64;
00241 #define GAN_INT64 GAN_LONG
00242 #define GAN_UINT64 GAN_ULONG
00243 #define GAN_INT64_MIN LONG_MIN
00244 #define GAN_INT64_MAX LONG_MAX
00245 #define GAN_UINT64_MAX ULONG_MAX
00246 #define GAN_UINT64_MAXD GAN_ULONG_MAXD
00247 #define GAN_UINT64_MAXF GAN_ULONG_MAXF
00248 #endif
00249
00250
00251 #if (SIZEOF_FLOAT == 4)
00252 typedef float gan_float32;
00253 #define GAN_FLOAT32 GAN_FLOAT
00254 #define GAN_FLOAT32_MIN FLT_MIN
00255 #define GAN_FLOAT32_MAX FLT_MAX
00256 #endif
00257
00258
00259 #if (SIZEOF_DOUBLE == 8)
00260 typedef double gan_float64;
00261 #define GAN_FLOAT64 GAN_DOUBLE
00262 #define GAN_FLOAT64_MIN DBL_MIN
00263 #define GAN_FLOAT64_MAX DBL_MAX
00264 #endif
00265
00266
00267 #if (GAN_UINT8_MAX != 0xff)
00268 #error Inconsistent 8-bit integer size
00269 #endif
00270
00271 #if (GAN_UINT16_MAX != 0xffff)
00272 #error Inconsistent 16-bit integer size
00273 #endif
00274
00275 #if (GAN_UINT32_MAX != 0xffffffff)
00276 #error Inconsistent 32-bit integer size
00277 #endif
00278
00279 #if (GAN_UINT64_MAX != 0xffffffffffffffff)
00280 #error Inconsistent 64-bit integer size
00281 #endif
00282
00293 void gan_assert ( Gan_Bool expr, const char*message );
00294
00295 #ifndef NDEBUG
00296
00297
00298 extern Gan_Bool gan_debug;
00299 #endif
00300
00301
00302 #define gan_heap_report(f) ((void) 0)
00303 #define gan_heap_push() ((void) 0)
00304 #define gan_heap_pop() ((void) 0)
00305
00306
00307 #ifndef HAVE_MEMCPY
00308 void *memcpy ( void *dest, const void *src, size_t n );
00309 #endif
00310
00311
00312 #ifndef M_SQRT1_2
00313 #define M_SQRT1_2 0.70710678118654752440
00314 #endif
00315
00316 #ifndef M_SQRT2
00317 #define M_SQRT2 1.41421356237309504880
00318 #endif
00319
00320 #ifndef M_SQRT3
00321 #define M_SQRT3 1.73205080756887719317
00322 #endif
00323
00324 #ifndef M_PI
00325 #define M_PI 3.14159265358979323846
00326 #endif
00327
00328 #ifndef M_PI_2
00329 #define M_PI_2 1.57079632679489661923
00330 #endif
00331
00332 #ifndef M_LN2
00333 # define M_LN2 0.69314718055994530942
00334 #endif
00335
00336
00337 #define GAN_ONE_THIRD 0.3333333333333333333333
00338 #define GAN_ONE_THIRD_F 0.3333333333333333333333F
00339 #define GAN_ONE_SIXTH 0.1666666666666666666666
00340 #define GAN_ONE_SIXTH_F 0.1666666666666666666666F
00341
00342
00343 #ifndef HAVE_POWF
00344 #define powf(x,y) (float)pow((float)(x), (float)(y))
00345 #endif
00346
00347 #ifndef HAVE_FABSF
00348 #define fabsf(x) (float)fabs((float)(x))
00349 #endif
00350
00351 #ifndef HAVE_SQRTF
00352 #define sqrtf(x) (float)sqrt((float)(x))
00353 #endif
00354
00363 #ifdef __cplusplus
00364 }
00365 #endif
00366
00367 #endif