/[ascend]/trunk/ascend/general/mathmacros.h
ViewVC logotype

Contents of /trunk/ascend/general/mathmacros.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2011 - (show annotations) (download) (as text)
Tue Apr 28 08:58:48 2009 UTC (15 years ago) by jpye
File MIME type: text/x-chdr
File size: 1408 byte(s)
Moving libascend components from #/base/generic into #/ascend
1 #ifndef ASC_MATHMACROS_H
2 #define ASC_MATHMACROS_H
3
4 /* Macros for MAX, MIN and ABS...
5 There is nothing portable or standard about this behavior and syntax.
6 Thus, if a program depends on it for correctness, that program is
7 unportable and in need of repair. We should not in any case
8 be using min/max/abs on any functions with side-effects in
9 ascend code. This, though a clever bit of gnu-ism, just serves
10 to generate warnings obscuring real problems when testing, so
11 it's going away until ISO C supports braced expressions which
12 it doesn't now.
13 */
14 #ifdef NONSTANDARD_MAX
15 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
16 # define MAX(X,Y) \
17 ( { __typeof__ (X) xmax_ = (X); \
18 __typeof__ (Y) ymax_ = (Y); \
19 (xmax_ > ymax_) ? xmax_ : ymax_; \
20 } )
21 # define MIN(X,Y) \
22 ( { __typeof__ (X) xmin_ = (X); \
23 __typeof__ (Y) ymin_ = (Y); \
24 (xmin_ < ymin_) ? xmin_ : ymin_; \
25 } )
26 # define ABS(X) \
27 ( { __typeof__ (X) xabs_ = (X); \
28 (xabs_ > 0) ? xabs_ : -xabs_; \
29 } )
30 #else
31 # define MAX(a,b) ( (a) < (b) ? (b) : (a) )
32 # define MIN(a,b) ( (a) < (b) ? (a) : (b) )
33 # define ABS(x) ( ((x) > 0) ? (x) : -(x) )
34 #endif
35 #else
36 /* in the mean time we have a nice reliable standby that worked for 30 years
37 when used as specified */
38 # define MAX(a,b) ( (a) < (b) ? (b) : (a) )
39 # define MIN(a,b) ( (a) < (b) ? (a) : (b) )
40 # define ABS(x) ( ((x) > 0) ? (x) : -(x) )
41 #endif
42
43 #endif /* ASC_MATHMACROS_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22