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