wolffd@0
|
1 /* $Id: arith.h,v 1.16 2009/06/03 01:10:51 ellson Exp $ $Revision: 1.16 $ */
|
wolffd@0
|
2 /* vim:set shiftwidth=4 ts=8: */
|
wolffd@0
|
3
|
wolffd@0
|
4 /**********************************************************
|
wolffd@0
|
5 * This software is part of the graphviz package *
|
wolffd@0
|
6 * http://www.graphviz.org/ *
|
wolffd@0
|
7 * *
|
wolffd@0
|
8 * Copyright (c) 1994-2004 AT&T Corp. *
|
wolffd@0
|
9 * and is licensed under the *
|
wolffd@0
|
10 * Common Public License, Version 1.0 *
|
wolffd@0
|
11 * by AT&T Corp. *
|
wolffd@0
|
12 * *
|
wolffd@0
|
13 * Information and Software Systems Research *
|
wolffd@0
|
14 * AT&T Research, Florham Park NJ *
|
wolffd@0
|
15 **********************************************************/
|
wolffd@0
|
16
|
wolffd@0
|
17 /* geometric functions (e.g. on points and boxes) with application to, but
|
wolffd@0
|
18 * no specific dependance on graphs */
|
wolffd@0
|
19
|
wolffd@0
|
20 #ifndef GV_ARITH_H
|
wolffd@0
|
21 #define GV_ARITH_H
|
wolffd@0
|
22
|
wolffd@0
|
23 /* for sincos */
|
wolffd@0
|
24 #ifndef _GNU_SOURCE
|
wolffd@0
|
25 #define _GNU_SOURCE 1
|
wolffd@0
|
26 #endif
|
wolffd@0
|
27
|
wolffd@0
|
28 #include <limits.h>
|
wolffd@0
|
29 #ifdef HAVE_VALUES_H
|
wolffd@0
|
30 #include <values.h>
|
wolffd@0
|
31 #endif
|
wolffd@0
|
32 #include <math.h>
|
wolffd@0
|
33
|
wolffd@0
|
34 #ifdef __cplusplus
|
wolffd@0
|
35 extern "C" {
|
wolffd@0
|
36 #endif
|
wolffd@0
|
37
|
wolffd@0
|
38 #ifdef MIN
|
wolffd@0
|
39 #undef MIN
|
wolffd@0
|
40 #endif
|
wolffd@0
|
41 #define MIN(a,b) ((a)<(b)?(a):(b))
|
wolffd@0
|
42
|
wolffd@0
|
43 #ifdef MAX
|
wolffd@0
|
44 #undef MAX
|
wolffd@0
|
45 #endif
|
wolffd@0
|
46 #define MAX(a,b) ((a)>(b)?(a):(b))
|
wolffd@0
|
47
|
wolffd@0
|
48 #ifdef ABS
|
wolffd@0
|
49 #undef ABS
|
wolffd@0
|
50 #endif
|
wolffd@0
|
51 #define ABS(a) ((a) >= 0 ? (a) : -(a))
|
wolffd@0
|
52
|
wolffd@0
|
53 #define AVG(a,b) ((a + b) / 2)
|
wolffd@0
|
54 #define SGN(a) (((a)<0)? -1 : 1)
|
wolffd@0
|
55 #define CMP(a,b) (((a)<(b)) ? -1 : (((a)>(b)) ? 1 : 0))
|
wolffd@0
|
56
|
wolffd@0
|
57 #ifndef INT_MAX
|
wolffd@0
|
58 #define INT_MAX ((int)(~(unsigned)0 >> 1))
|
wolffd@0
|
59 #endif
|
wolffd@0
|
60
|
wolffd@0
|
61 #ifndef INT_MIN
|
wolffd@0
|
62 #define INT_MIN (-INT_MAX - 1)
|
wolffd@0
|
63 #endif
|
wolffd@0
|
64
|
wolffd@0
|
65 #ifndef MAXSHORT
|
wolffd@0
|
66 #define MAXSHORT (0x7fff)
|
wolffd@0
|
67 #endif
|
wolffd@0
|
68
|
wolffd@0
|
69 #ifndef MAXDOUBLE
|
wolffd@0
|
70 #define MAXDOUBLE 1.7976931348623157e+308
|
wolffd@0
|
71 #endif
|
wolffd@0
|
72
|
wolffd@0
|
73 #ifndef MAXFLOAT
|
wolffd@0
|
74 #define MAXFLOAT ((float)3.40282347e+38)
|
wolffd@0
|
75 #endif
|
wolffd@0
|
76
|
wolffd@0
|
77 #ifdef BETWEEN
|
wolffd@0
|
78 #undef BETWEEN
|
wolffd@0
|
79 #endif
|
wolffd@0
|
80 #define BETWEEN(a,b,c) (((a) <= (b)) && ((b) <= (c)))
|
wolffd@0
|
81
|
wolffd@0
|
82 #ifndef M_PI
|
wolffd@0
|
83 #define M_PI 3.14159265358979323846
|
wolffd@0
|
84 #endif
|
wolffd@0
|
85
|
wolffd@0
|
86 #ifndef SQRT2
|
wolffd@0
|
87 #define SQRT2 1.41421356237309504880
|
wolffd@0
|
88 #endif
|
wolffd@0
|
89
|
wolffd@0
|
90 #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5))
|
wolffd@0
|
91 #define RADIANS(deg) ((deg)/180.0 * M_PI)
|
wolffd@0
|
92 #define DEGREES(rad) ((rad)/M_PI * 180.0)
|
wolffd@0
|
93
|
wolffd@0
|
94 #define SQR(a) ((a) * (a))
|
wolffd@0
|
95
|
wolffd@0
|
96 #ifdef HAVE_SINCOS
|
wolffd@0
|
97 extern void sincos(double x, double *s, double *c);
|
wolffd@0
|
98 #else
|
wolffd@0
|
99 # define sincos(x,s,c) *s = sin(x); *c = cos(x)
|
wolffd@0
|
100 #endif
|
wolffd@0
|
101
|
wolffd@0
|
102 #ifdef __cplusplus
|
wolffd@0
|
103 }
|
wolffd@0
|
104 #endif
|
wolffd@0
|
105
|
wolffd@0
|
106 #endif
|