Debian Codegraph @

generic/bltMath.h

raw symbols SCIP
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 #ifndef DBL_EPSILON
94 #define DBL_EPSILON BLT_DBL_EPSILON
95 #endif
96 #ifdef HUGE_VAL
97 #define DBL_MAX HUGE_VAL
98 #define DBL_MIN (1/HUGE_VAL)
99 #else
100 #ifdef HUGE
101 #define DBL_MAX HUGE
102 #define DBL_MIN (1/HUGE)
103 #else
104 /*
105 * Punt: Assume relatively small values
106 */
107 #define DBL_MAX 3.40282347E+38
108 #define DBL_MIN 1.17549435E-38
109 #endif /*HUGE*/
110 #endif /*HUGE_VAL*/
111 #endif /*sun*/
112 #endif /*!HAVE_FLOAT_H*/
113
114 /*
115 * ----------------------------------------------------------------------
116 *
117 * The following are macros replacing math library functions:
118 * "fabs", "fmod", "abs", "rint", and "exp10".
119 *
120 * Although many of these routines may exist in your math
121 * library, they aren't used in libtcl.a or libtk.a. This makes
122 * it difficult to dynamically load the BLT library as a shared
123 * object unless the math library is also shared (which isn't
124 * true on several systems). We can avoid the problem by
125 * replacing the "exotic" math routines with macros.
126 *
127 * ----------------------------------------------------------------------
128 */
129 #undef ABS
130 #define ABS(x) (((x)<0)?(-(x)):(x))
131
132 #undef EXP10
133 #define EXP10(x) (pow(10.0,(x)))
134
135 #undef FABS
136 #define FABS(x) (((x)<0.0)?(-(x)):(x))
137
138 #undef SIGN
139 #define SIGN(x) (((x) < 0.0) ? -1 : 1)
140
141 /*
142 * Be careful when using the next two macros. They both assume the floating
143 * point number is less than the size of an int. That means, for example, you
144 * can't use these macros with numbers bigger than than 2^31-1.
145 */
146 #undef FMOD
147 #define FMOD(x,y) ((x)-(((int)((x)/(y)))*y))
148
149 #undef ROUND
150 #define ROUND(x) ((int)((x) + (((x)<0.0) ? -0.5 : 0.5)))
151
152 #ifdef HAVE_FINITE
153 #define FINITE(x) finite(x)
154 #else
155 #ifdef HAVE_ISFINITE
156 #define FINITE(x) isfinite(x)
157 #else
158 #ifdef HAVE_ISNAN
159 #define FINITE(x) (!isnan(x))
160 #else
161 #define FINITE(x) (TRUE)
162 #endif /* HAVE_ISNAN */
163 #endif /* HAVE_ISFINITE */
164 #endif /* HAVE_FINITE */
165
166 extern double bltNaN;
167
168 #define DEFINED(x) (!isnan(x))
169 #define UNDEFINED(x) (isnan(x))
170 #define VALUE_UNDEFINED bltNaN
171
172 /*
173 * ----------------------------------------------------------------------
174 *
175 * On some systems "strdup" and "strcasecmp" are in the C library,
176 * but have no declarations in the C header files. Make sure we
177 * supply them here.
178 *
179 * ----------------------------------------------------------------------
180 */
181 #ifdef NEED_DECL_STRDUP
182 extern char *strdup _ANSI_ARGS_((CONST char *s));
183 #endif /* NEED_DECL_STRDUP */
184
185 #ifndef HAVE_STRTOLOWER
186 extern void strtolower _ANSI_ARGS_((char *s));
187 #endif /* HAVE_STRTOLOWER */
188
189 #ifdef NEED_DECL_DRAND48
190 extern double drand48 _ANSI_ARGS_((void));
191 extern void srand48 _ANSI_ARGS_((long seed));
192 #endif /* NEED_DECL_DRAND48 */
193
194 #ifdef NEED_DECL_STRCASECMP
195 extern int strcasecmp _ANSI_ARGS_((CONST char *s1, CONST char *s2));
196 #endif /* NEED_DECL_STRCASECMP */
197
198 #endif /* BLT_MATH_H */