1 /********** 2 Copyright 1990 Regents of the University of California. All rights reserved. 3 Author: 1985 Thomas L. Quarles 4 **********/ 5 6 #ifndef UTIL 7 #define UTIL 8 9 #define MALLOC(x) calloc(1,(unsigned)(x)) 10 #define FREE(x) {if (x) {free((char *)(x));(x) = 0;}} 11 12 #ifdef STDC_HEADERS 13 #ifndef STDLIB_IS_INCLUDED 14 #define STDLIB_IS_INCLUDED 15 #include <stdlib.h> 16 #endif 17 #else 18 extern char *malloc(); 19 extern char *calloc(); 20 extern char *realloc(); 21 extern void free(); 22 #endif 23 24 extern char *trealloc(); 25 extern char *tmalloc(); 26 27 #define TRUE 1 28 #define FALSE 0 29 #define REALLOC(x,y) trealloc((char *)(x),(unsigned)(y)) 30 31 #ifdef DEBUG 32 #define DEBUGMSG(textargs) printf(textargs) 33 #else 34 #define DEBUGMSG(testargs) 35 #endif 36 37 #ifdef HAVE_NOINLINE 38 #define FABS(a) fabs(a) 39 double fabs(); 40 #else 41 #define FABS(a) ( ((a)<0) ? -(a) : (a) ) 42 #endif 43 44 /* XXX Move these into the above ifdef someday */ 45 #ifdef MIN 46 #undef MIN 47 #endif 48 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 49 #ifdef MAX 50 #undef MAX 51 #endif 52 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 53 #ifdef SIGN 54 #undef SIGN 55 #endif 56 #define SIGN(a,b) ( b >= 0 ? (a >= 0 ? a : - a) : (a >= 0 ? - a : a)) 57 58 #ifdef ABORT 59 #undef ABORT 60 #endif 61 #define ABORT() fflush(stderr);fflush(stdout);abort(); 62 63 #ifdef ERROR 64 #undef ERROR 65 #endif 66 #define ERROR(CODE,MESSAGE) { \ 67 errMsg = MALLOC(strlen(MESSAGE) + 1); \ 68 strcpy(errMsg, (MESSAGE)); \ 69 return (CODE); } 70 71 #ifdef NEW 72 #undef NEW 73 #endif 74 #define NEW(TYPE) ((TYPE *) MALLOC(sizeof(TYPE))) 75 76 #endif /*UTIL*/ 77 78 #define R_NORM(A,B) { \ 79 if ((A) == 0.0) { \ 80 (B) = 0; \ 81 } else { \ 82 while (FABS(A) > 1.0) { \ 83 (B) += 1; \ 84 (A) /= 2.0; \ 85 } \ 86 while (FABS(A) < 0.5) { \ 87 (B) -= 1; \ 88 (A) *= 2.0; \ 89 } \ 90 } \ 91 } 92