OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
macros.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// macros.h
3//
4// Project: EPA SWMM5
5// Version: 5.2
6// Date: 11/01/21 (Build 5.2.0)
7// Author: L. Rossman
8//-----------------------------------------------------------------------------
9
10#ifndef MACROS_H
11#define MACROS_H
12
13
14//--------------------------------------------------
15// Macro to test for successful allocation of memory
16//--------------------------------------------------
17#define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
18
19//--------------------------------------------------
20// Macro to free a non-null pointer
21//--------------------------------------------------
22#define FREE(x) { if (x) { free(x); x = NULL; } }
23
24//---------------------------------------------------
25// Conversion macros to be used in place of functions
26//---------------------------------------------------
27#define ABS(x) (((x)<0) ? -(x) : (x)) /* absolute value of x */
28#define MIN(x,y) (((x)<=(y)) ? (x) : (y)) /* minimum of x and y */
29#define MAX(x,y) (((x)>=(y)) ? (x) : (y)) /* maximum of x and y */
30#define MOD(x,y) ((x)%(y)) /* x modulus y */
31#define LOG10(x) ((x) > 0.0 ? log10((x)) : (x)) /* safe log10 of x */
32#define SQR(x) ((x)*(x)) /* x-squared */
33#define SGN(x) (((x)<0) ? (-1) : (1)) /* sign of x */
34#define SIGN(x,y) ((y) >= 0.0 ? fabs(x) : -fabs(x))
35#define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
36 /* uppercase char of x */
37#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0])) /* length of array x */
38
39//-------------------------------------------------
40// Macro to evaluate function x with error checking
41//-------------------------------------------------
42#define CALL(x) (ErrorCode = ((ErrorCode>0) ? (ErrorCode) : (x)))
43
44
45#endif //MACROS_H