1 |
|
---|
2 | /*
|
---|
3 | * bltMath.h --
|
---|
4 | *
|
---|
5 | * Copyright 1993-1998 Lucent Technologies, Inc.
|
---|
6 | *
|
---|
7 | * Permission to use, copy, modify, and distribute this software and
|
---|
8 | * its documentation for any purpose and without fee is hereby
|
---|
9 | * granted, provided that the above copyright notice appear in all
|
---|
10 | * copies and that both that the copyright notice and warranty
|
---|
11 | * disclaimer appear in supporting documentation, and that the names
|
---|
12 | * of Lucent Technologies any of their entities not be used in
|
---|
13 | * advertising or publicity pertaining to distribution of the software
|
---|
14 | * without specific, written prior permission.
|
---|
15 | *
|
---|
16 | * Lucent Technologies disclaims all warranties with regard to this
|
---|
17 | * software, including all implied warranties of merchantability and
|
---|
18 | * fitness. In no event shall Lucent Technologies be liable for any
|
---|
19 | * special, indirect or consequential damages or any damages
|
---|
20 | * whatsoever resulting from loss of use, data or profits, whether in
|
---|
21 | * an action of contract, negligence or other tortuous action, arising
|
---|
22 | * out of or in connection with the use or performance of this
|
---|
23 | * software.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef _BLT_MATH_H
|
---|
27 | #define _BLT_MATH_H
|
---|
28 |
|
---|
29 | #include <math.h>
|
---|
30 |
|
---|
31 | #ifdef HAVE_FLOAT_H
|
---|
32 | #include <float.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #ifdef HAVE_IEEEFP_H
|
---|
36 | #include <ieeefp.h>
|
---|
37 | #endif /* HAVE_IEEEFP_H */
|
---|
38 |
|
---|
39 | #ifndef M_PI
|
---|
40 | #define M_PI 3.14159265358979323846
|
---|
41 | #endif /* M_PI */
|
---|
42 |
|
---|
43 | #ifndef M_PI_2
|
---|
44 | #define M_PI_2 1.57079632679489661923
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #ifndef M_SQRT2
|
---|
48 | #define M_SQRT2 1.41421356237309504880
|
---|
49 | #endif /* M_SQRT2 */
|
---|
50 |
|
---|
51 | #ifndef M_SQRT1_2
|
---|
52 | #define M_SQRT1_2 0.70710678118654752440
|
---|
53 | #endif /* M_SQRT1_2 */
|
---|
54 |
|
---|
55 | #ifndef SHRT_MAX
|
---|
56 | #define SHRT_MAX 0x7FFF
|
---|
57 | #endif /* SHRT_MAX */
|
---|
58 |
|
---|
59 | #ifndef SHRT_MIN
|
---|
60 | #define SHRT_MIN -(SHRT_MAX)
|
---|
61 | #endif /* SHRT_MAX */
|
---|
62 |
|
---|
63 | #ifndef USHRT_MAX
|
---|
64 | #define USHRT_MAX 0xFFFF
|
---|
65 | #endif /* USHRT_MAX */
|
---|
66 |
|
---|
67 | #ifndef INT_MAX
|
---|
68 | #define INT_MAX 2147483647
|
---|
69 | #endif /* INT_MAX */
|
---|
70 |
|
---|
71 | #ifndef HAVE_FLOAT_H
|
---|
72 | /*
|
---|
73 | * ----------------------------------------------------------------------
|
---|
74 | *
|
---|
75 | * DBL_MIN, DBL_MAX --
|
---|
76 | *
|
---|
77 | * DBL_MAX and DBL_MIN are the largest and smaller double
|
---|
78 | * precision numbers that can be represented by the floating
|
---|
79 | * point hardware. If the compiler is ANSI, they can be found in
|
---|
80 | * float.h. Otherwise, we use HUGE_VAL or HUGE to determine
|
---|
81 | * them.
|
---|
82 | *
|
---|
83 | * ----------------------------------------------------------------------
|
---|
84 | */
|
---|
85 | /*
|
---|
86 | * Don't want to include __infinity (definition of HUGE_VAL (SC1.x))
|
---|
87 | */
|
---|
88 | #ifdef sun
|
---|
89 | #define DBL_MAX 1.7976931348623157E+308
|
---|
90 | #define DBL_MIN 2.2250738585072014E-308
|
---|
91 | #define DBL_EPSILON 2.2204460492503131e-16
|
---|
92 | #else
|
---|
93 | #ifdef HUGE_VAL
|
---|
94 | #define DBL_MAX HUGE_VAL
|
---|
95 | #define DBL_MIN (1/HUGE_VAL)
|
---|
96 | #else
|
---|
97 | #ifdef HUGE
|
---|
98 | #define DBL_MAX HUGE
|
---|
99 | #define DBL_MIN (1/HUGE)
|
---|
100 | #else
|
---|
101 | /*
|
---|
102 | * Punt: Assume relatively small values
|
---|
103 | */
|
---|
104 | #define DBL_MAX 3.40282347E+38
|
---|
105 | #define DBL_MIN 1.17549435E-38
|
---|
106 | #endif /*HUGE*/
|
---|
107 | #endif /*HUGE_VAL*/
|
---|
108 | #endif /*sun*/
|
---|
109 |
|
---|
110 | #ifndef BLT_DBL_EPSILON
|
---|
111 | # define BLT_DBL_EPSILON 2.2204460492503131e-16
|
---|
112 | #endif
|
---|
113 | #ifndef BLT_FLT_EPSILON
|
---|
114 | # define BLT_FLT_EPSILON 1.19209290e-07F
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | #ifndef DBL_EPSILON
|
---|
118 | # define DBL_EPSILON BLT_DBL_EPSILON
|
---|
119 | #endif
|
---|
120 | #ifndef FLT_EPSILON
|
---|
121 | # define FLT_EPSILON BLT_FLT_EPSILON
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | #endif /*!HAVE_FLOAT_H*/
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * ----------------------------------------------------------------------
|
---|
128 | *
|
---|
129 | * The following are macros replacing math library functions:
|
---|
130 | * "fabs", "fmod", "abs", "rint", and "exp10".
|
---|
131 | *
|
---|
132 | * Although many of these routines may exist in your math
|
---|
133 | * library, they aren't used in libtcl.a or libtk.a. This makes
|
---|
134 | * it difficult to dynamically load the BLT library as a shared
|
---|
135 | * object unless the math library is also shared (which isn't
|
---|
136 | * true on several systems). We can avoid the problem by
|
---|
137 | * replacing the "exotic" math routines with macros.
|
---|
138 | *
|
---|
139 | * ----------------------------------------------------------------------
|
---|
140 | */
|
---|
141 | #undef ABS
|
---|
142 | #define ABS(x) (((x)<0)?(-(x)):(x))
|
---|
143 |
|
---|
144 | #undef EXP10
|
---|
145 | #define EXP10(x) (pow(10.0,(x)))
|
---|
146 |
|
---|
147 | #undef FABS
|
---|
148 | #define FABS(x) (((x)<0.0)?(-(x)):(x))
|
---|
149 |
|
---|
150 | #undef SIGN
|
---|
151 | #define SIGN(x) (((x) < 0.0) ? -1 : 1)
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * Be careful when using the next two macros. They both assume the floating
|
---|
155 | * point number is less than the size of an int. That means, for example, you
|
---|
156 | * can't use these macros with numbers bigger than than 2^31-1.
|
---|
157 | */
|
---|
158 | #undef FMOD
|
---|
159 | #define FMOD(x,y) ((x)-(((int)((x)/(y)))*y))
|
---|
160 |
|
---|
161 | #undef ROUND
|
---|
162 | #define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5)))
|
---|
163 |
|
---|
164 | #ifdef HAVE_FINITE
|
---|
165 | #define FINITE(x) finite(x)
|
---|
166 | #else
|
---|
167 | #ifdef HAVE_ISFINITE
|
---|
168 | #define FINITE(x) isfinite(x)
|
---|
169 | #else
|
---|
170 | #ifdef HAVE_ISNAN
|
---|
171 | #define FINITE(x) (!isnan(x))
|
---|
172 | #else
|
---|
173 | #define FINITE(x) (TRUE)
|
---|
174 | #endif /* HAVE_ISNAN */
|
---|
175 | #endif /* HAVE_ISFINITE */
|
---|
176 | #endif /* HAVE_FINITE */
|
---|
177 |
|
---|
178 | extern double bltNaN;
|
---|
179 |
|
---|
180 | #define DEFINED(x) (!isnan(x))
|
---|
181 | #define UNDEFINED(x) (isnan(x))
|
---|
182 | #define VALUE_UNDEFINED bltNaN
|
---|
183 |
|
---|
184 | /*
|
---|
185 | * ----------------------------------------------------------------------
|
---|
186 | *
|
---|
187 | * On some systems "strdup" and "strcasecmp" are in the C library,
|
---|
188 | * but have no declarations in the C header files. Make sure we
|
---|
189 | * supply them here.
|
---|
190 | *
|
---|
191 | * ----------------------------------------------------------------------
|
---|
192 | */
|
---|
193 | #ifdef NEED_DECL_STRDUP
|
---|
194 | extern char *strdup _ANSI_ARGS_((CONST char *s));
|
---|
195 | #endif /* NEED_DECL_STRDUP */
|
---|
196 |
|
---|
197 | #ifndef HAVE_STRTOLOWER
|
---|
198 | extern void strtolower _ANSI_ARGS_((char *s));
|
---|
199 | #endif /* HAVE_STRTOLOWER */
|
---|
200 |
|
---|
201 | #ifdef NEED_DECL_DRAND48
|
---|
202 | extern double drand48 _ANSI_ARGS_((void));
|
---|
203 | extern void srand48 _ANSI_ARGS_((long seed));
|
---|
204 | #endif /* NEED_DECL_DRAND48 */
|
---|
205 |
|
---|
206 | #ifdef NEED_DECL_STRCASECMP
|
---|
207 | extern int strcasecmp _ANSI_ARGS_((CONST char *s1, CONST char *s2));
|
---|
208 | #endif /* NEED_DECL_STRCASECMP */
|
---|
209 |
|
---|
210 | #endif /* BLT_MATH_H */
|
---|