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 #if (SIZEOF_LONG_LONG != 0)
00098 GAN_LONGLONG,
00099 #endif
00100 GAN_FLOAT,
00101 GAN_DOUBLE,
00102 GAN_LONGDOUBLE,
00103 GAN_STRING,
00104 GAN_BOOL,
00105 GAN_POINTER
00106 } Gan_Type;
00107
00109 extern const size_t gan_type_sizes[];
00110
00111
00112
00113
00114
00115
00116 #if (SIZEOF_CHAR == 1)
00117 #define GAN_CHAR_MAXD 127.0
00118 #define GAN_CHAR_MAXF 127.0F
00119 #define GAN_UCHAR_MAXD 255.0
00120 #define GAN_UCHAR_MAXF 255.0F
00121 #endif
00122
00123 #if (SIZEOF_SHORT == 2)
00124 #define GAN_SHRT_MAXD 32767.0
00125 #define GAN_SHRT_MAXF 32767.0F
00126 #define GAN_USHRT_MAXD 65535.0
00127 #define GAN_USHRT_MAXF 65535.0F
00128 #elif (SIZEOF_SHORT == 4)
00129 #define GAN_SHRT_MAXD 2147483647.0
00130 #define GAN_SHRT_MAXF 2147483647.0F
00131 #define GAN_USHRT_MAXD 4294967295.0
00132 #define GAN_USHRT_MAXF 4294967295.0F
00133 #elif (SIZEOF_SHORT == 8)
00134 #define GAN_SHRT_MAXD 9.2233720368547758e18
00135 #define GAN_SHRT_MAXF 9.2233720368547758e18F
00136 #define GAN_USHRT_MAXD 1.8446744073709552e19
00137 #define GAN_USHRT_MAXF 1.8446744073709552e19F
00138 #endif
00139
00140 #if (SIZEOF_INT == 2)
00141 #define GAN_INT_MAXD 32767.0
00142 #define GAN_INT_MAXF 32767.0F
00143 #define GAN_UINT_MAXD 65535.0
00144 #define GAN_UINT_MAXF 65535.0F
00145 #elif (SIZEOF_INT == 4)
00146 #define GAN_INT_MAXD 2147483647.0
00147 #define GAN_INT_MAXF 2147483647.0F
00148 #define GAN_UINT_MAXD 4294967295.0
00149 #define GAN_UINT_MAXF 4294967295.0F
00150 #elif (SIZEOF_INT == 8)
00151 #define GAN_INT_MAXD 9.2233720368547758e18
00152 #define GAN_INT_MAXF 9.2233720368547758e18F
00153 #define GAN_UINT_MAXD 1.8446744073709552e19
00154 #define GAN_UINT_MAXF 1.8446744073709552e19F
00155 #endif
00156
00157 #if (SIZEOF_LONG == 4)
00158 #define GAN_ULONG_MAXD 4294967295.0
00159 #define GAN_ULONG_MAXF 4294967295.0F
00160 #elif (SIZEOF_LONG == 8)
00161 #define GAN_LONG_MAXD 9.2233720368547758e18
00162 #define GAN_LONG_MAXF 9.2233720368547758e18F
00163 #define GAN_ULONG_MAXD 1.8446744073709552e19
00164 #define GAN_ULONG_MAXF 1.8446744073709552e19F
00165 #endif
00166
00167
00168 #if (SIZEOF_CHAR == 1)
00169 typedef char gan_i8;
00170 typedef unsigned char gan_ui8;
00171 #define GAN_INT8 GAN_CHAR
00172 #define GAN_UINT8 GAN_UCHAR
00173 #define GAN_I8_MIN CHAR_MIN
00174 #define GAN_I8_MAX CHAR_MAX
00175 #define GAN_UI8_MAX UCHAR_MAX
00176 #define GAN_UI8_MAXD GAN_UCHAR_MAXD
00177 #define GAN_UI8_MAXF GAN_UCHAR_MAXF
00178 #endif
00179
00180
00181 #if (SIZEOF_SHORT == 2)
00182 typedef short gan_i16;
00183 typedef unsigned short gan_ui16;
00184 #define GAN_INT16 GAN_SHORT
00185 #define GAN_UINT16 GAN_USHORT
00186 #define GAN_I16_MIN SHRT_MIN
00187 #define GAN_I16_MAX SHRT_MAX
00188 #define GAN_UI16_MAX USHRT_MAX
00189 #define GAN_UI16_MAXD GAN_USHRT_MAXD
00190 #define GAN_UI16_MAXF GAN_USHRT_MAXF
00191 #elif (SIZEOF_INT == 2)
00192 typedef int gan_i16;
00193 typedef unsigned int gan_ui16;
00194 #define GAN_INT16 GAN_INT
00195 #define GAN_UINT16 GAN_UINT
00196 #define GAN_I16_MIN INT_MIN
00197 #define GAN_I16_MAX INT_MAX
00198 #define GAN_UI16_MAX UINT_MAX
00199 #define GAN_UI16_MAXD GAN_UINT_MAXD
00200 #define GAN_UI16_MAXF GAN_UINT_MAXF
00201 #endif
00202
00203
00204 #if (SIZEOF_INT == 4)
00205 typedef int gan_i32;
00206 typedef unsigned int gan_ui32;
00207 #define GAN_INT32 GAN_INT
00208 #define GAN_UINT32 GAN_UINT
00209 #define GAN_I32_MIN INT_MIN
00210 #define GAN_I32_MAX INT_MAX
00211 #define GAN_UI32_MAX UINT_MAX
00212 #define GAN_UI32_MAXD GAN_UINT_MAXD
00213 #define GAN_UI32_MAXF GAN_UINT_MAXF
00214 #elif (SIZEOF_LONG == 4)
00215 typedef long gan_i32;
00216 typedef unsigned long gan_ui32;
00217 #define GAN_INT32 GAN_LONG
00218 #define GAN_UINT32 GAN_ULONG
00219 #define GAN_I32_MIN LONG_MIN
00220 #define GAN_I32_MAX LONG_MAX
00221 #define GAN_UI32_MAX ULONG_MAX
00222 #define GAN_UI32_MAXD GAN_ULONG_MAXD
00223 #define GAN_UI32_MAXF GAN_ULONG_MAXF
00224 #endif
00225
00226
00227 #if (SIZEOF_INT == 8)
00228 typedef int gan_i64;
00229 typedef unsigned int gan_ui64;
00230 #define GAN_INT64 GAN_INT
00231 #define GAN_UINT64 GAN_UINT
00232 #define GAN_I64_MIN INT_MIN
00233 #define GAN_I64_MAX INT_MAX
00234 #define GAN_UI64_MAX UINT_MAX
00235 #define GAN_UI64_MAXD GAN_UINT_MAXD
00236 #define GAN_UI64_MAXF GAN_UINT_MAXF
00237 #elif (SIZEOF_LONG == 8)
00238 typedef long gan_i64;
00239 typedef unsigned long gan_ui64;
00240 #define GAN_INT64 GAN_LONG
00241 #define GAN_UINT64 GAN_ULONG
00242 #define GAN_I64_MIN LONG_MIN
00243 #define GAN_I64_MAX LONG_MAX
00244 #define GAN_UI64_MAX ULONG_MAX
00245 #define GAN_UI64_MAXD GAN_ULONG_MAXD
00246 #define GAN_UI64_MAXF GAN_ULONG_MAXF
00247
00248
00249 #endif
00250
00251
00252 #if (GAN_UI8_MAX != 0xff)
00253 #error Inconsistent 8-bit integer size
00254 #endif
00255
00256 #if (GAN_UI16_MAX != 0xffff)
00257 #error Inconsistent 16-bit integer size
00258 #endif
00259
00260 #if (GAN_UI32_MAX != 0xffffffff)
00261 #error Inconsistent 32-bit integer size
00262 #endif
00263
00264 #if (GAN_UI64_MAX != 0xffffffffffffffff)
00265 #error Inconsistent 64-bit integer size
00266 #endif
00267
00278 void gan_assert ( Gan_Bool expr, const char*message );
00279
00280 #ifndef NDEBUG
00281
00282
00283 extern Gan_Bool gan_debug;
00284 #endif
00285
00286
00287 #define gan_heap_report(f) ((void) 0)
00288 #define gan_heap_push() ((void) 0)
00289 #define gan_heap_pop() ((void) 0)
00290
00291
00292 #ifndef HAVE_MEMCPY
00293 void *memcpy ( void *dest, const void *src, size_t n );
00294 #endif
00295
00296
00297 #ifndef M_SQRT1_2
00298 #define M_SQRT1_2 0.70710678118654752440
00299 #endif
00300
00301 #ifndef M_SQRT2
00302 #define M_SQRT2 1.41421356237309504880
00303 #endif
00304
00305 #ifndef M_SQRT3
00306 #define M_SQRT3 1.73205080756887719317
00307 #endif
00308
00309 #ifndef M_PI
00310 #define M_PI 3.14159265358979323846
00311 #endif
00312
00313 #ifndef M_PI_2
00314 #define M_PI_2 1.57079632679489661923
00315 #endif
00316
00317
00318 #define GAN_ONE_THIRD 0.3333333333333333333333
00319 #define GAN_ONE_THIRD_F 0.3333333333333333333333F
00320
00321
00322 #ifndef HAVE_POWF
00323 #define powf(x,y) (float)pow((float)(x), (float)(y))
00324 #endif
00325
00326 #ifndef HAVE_FABSF
00327 #define fabsf(x) (float)fabs((float)(x))
00328 #endif
00329
00330 #ifndef HAVE_SQRTF
00331 #define sqrtf(x) (float)sqrt((float)(x))
00332 #endif
00333
00342 #ifdef __cplusplus
00343 }
00344 #endif
00345
00346 #endif