]>
Commit | Line | Data |
---|---|---|
f7eac6eb | 1 | /* Declarations for math functions. |
2f6d1f1b | 2 | Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc. |
ba1ffaa1 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
ba1ffaa1 UD |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
28f540f4 | 9 | |
ba1ffaa1 UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Library General Public License for more details. | |
28f540f4 | 14 | |
ba1ffaa1 UD |
15 | You should have received a copy of the GNU Library General Public |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
28f540f4 RM |
19 | |
20 | /* | |
ba1ffaa1 | 21 | * ISO C Standard: 4.5 MATHEMATICS <math.h> |
28f540f4 RM |
22 | */ |
23 | ||
24 | #ifndef _MATH_H | |
25 | ||
26 | #define _MATH_H 1 | |
27 | #include <features.h> | |
28 | ||
29 | __BEGIN_DECLS | |
30 | ||
f7eac6eb RM |
31 | /* Get machine-dependent HUGE_VAL value (returned on overflow). |
32 | On all IEEE754 machines, this is +Infinity. */ | |
28f540f4 RM |
33 | #include <huge_val.h> |
34 | ||
35 | /* Get machine-dependent NAN value (returned for some domain errors). */ | |
36 | #ifdef __USE_GNU | |
37 | #include <nan.h> | |
38 | #endif | |
39 | ||
40 | ||
f7eac6eb RM |
41 | /* The file <mathcalls.h> contains the prototypes for all the actual |
42 | math functions. These macros are used for those prototypes, so | |
43 | we can easily declare each function as both `name' and `__name', | |
44 | and can declare the float versions `namef' and `__namef'. */ | |
45 | ||
46 | #define __MATHCALL(function,suffix, args) \ | |
377a515b | 47 | __MATHDECL (_Mdouble_,function,suffix, args) |
f7eac6eb RM |
48 | #define __MATHDECL(type, function,suffix, args) \ |
49 | __MATHDECL_1(type, function,suffix, args); \ | |
377a515b | 50 | __MATHDECL_1(type, __CONCAT(__,function),suffix, args) |
3e5f5557 UD |
51 | #define __MATHCALLX(function,suffix, args, attrib) \ |
52 | __MATHDECLX (_Mdouble_,function,suffix, args, attrib) | |
53 | #define __MATHDECLX(type, function,suffix, args, attrib) \ | |
54 | __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \ | |
55 | __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib) | |
f7eac6eb RM |
56 | #define __MATHDECL_1(type, function,suffix, args) \ |
57 | extern type __MATH_PRECNAME(function,suffix) args | |
58 | ||
59 | #define _Mdouble_ double | |
377a515b | 60 | #define __MATH_PRECNAME(name,r) __CONCAT(name,r) |
f7eac6eb RM |
61 | #include <mathcalls.h> |
62 | #undef _Mdouble_ | |
63 | #undef __MATH_PRECNAME | |
64 | ||
377a515b | 65 | #if defined __USE_MISC || defined __USE_ISOC9X |
76060ec0 | 66 | |
999493cb RM |
67 | |
68 | /* Include the file of declarations again, this time using `float' | |
f7eac6eb RM |
69 | instead of `double' and appending f to each function name. */ |
70 | ||
999493cb RM |
71 | #ifndef _Mfloat_ |
72 | #define _Mfloat_ float | |
73 | #endif | |
74 | #define _Mdouble_ _Mfloat_ | |
377a515b | 75 | #ifdef __STDC__ |
f7eac6eb | 76 | #define __MATH_PRECNAME(name,r) name##f##r |
377a515b UD |
77 | #else |
78 | #define __MATH_PRECNAME(name,r) name/**/f/**/r | |
79 | #endif | |
f7eac6eb RM |
80 | #include <mathcalls.h> |
81 | #undef _Mdouble_ | |
82 | #undef __MATH_PRECNAME | |
76060ec0 | 83 | |
377a515b | 84 | #if __STDC__ - 0 || __GNUC__ - 0 |
999493cb | 85 | /* Include the file of declarations again, this time using `long double' |
76060ec0 RM |
86 | instead of `double' and appending l to each function name. */ |
87 | ||
999493cb RM |
88 | #ifndef _Mlong_double_ |
89 | #define _Mlong_double_ long double | |
90 | #endif | |
91 | #define _Mdouble_ _Mlong_double_ | |
377a515b | 92 | #ifdef __STDC__ |
76060ec0 | 93 | #define __MATH_PRECNAME(name,r) name##l##r |
377a515b UD |
94 | #else |
95 | #define __MATH_PRECNAME(name,r) name/**/l/**/r | |
96 | #endif | |
76060ec0 RM |
97 | #include <mathcalls.h> |
98 | #undef _Mdouble_ | |
99 | #undef __MATH_PRECNAME | |
100 | ||
377a515b UD |
101 | #endif /* __STDC__ || __GNUC__ */ |
102 | ||
103 | #endif /* Use misc or ISO C 9X. */ | |
4cca6b86 UD |
104 | #undef __MATHDECL_1 |
105 | #undef __MATHDECL | |
106 | #undef __MATHCALL | |
107 | ||
108 | ||
109 | #if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC9X | |
110 | /* This variable is used by `gamma' and `lgamma'. */ | |
111 | extern int signgam; | |
112 | #endif | |
377a515b UD |
113 | |
114 | ||
115 | /* ISO C 9X defines some generic macros which work on any data type. */ | |
116 | #if __USE_ISOC9X | |
117 | ||
63551311 UD |
118 | /* Get the architecture specific values describing the floating-point |
119 | evaluation. The following symbols will get defined: | |
120 | ||
121 | float_t floating-point type at least as wide as `float' used | |
122 | to evaluate `float' expressions | |
123 | double_t floating-point type at least as wide as `double' used | |
124 | to evaluate `double' expressions | |
125 | ||
126 | FLT_EVAL_METHOD | |
127 | Defined to | |
128 | 0 if `float_t' is `float' and `double_t' is `double' | |
129 | 1 if `float_t' and `double_t' are `double' | |
130 | 2 if `float_t' and `double_t' are `long double' | |
131 | else `float_t' and `double_t' are unspecified | |
132 | ||
133 | INFINITY representation of the infinity value of type `float_t' | |
134 | */ | |
135 | #include <mathbits.h> | |
136 | ||
377a515b UD |
137 | /* All floating-point numbers can be put in one of these categories. */ |
138 | enum | |
139 | { | |
140 | FP_NAN, | |
141 | #define FP_NAN FP_NAN | |
142 | FP_INFINITE, | |
143 | #define FP_INFINITE FP_INFINITE | |
144 | FP_ZERO, | |
145 | #define FP_ZERO FP_ZERO | |
146 | FP_SUBNORMAL, | |
147 | #define FP_SUBNORMAL FP_SUBNORMAL | |
148 | FP_NORMAL | |
149 | #define FP_NORMAL FP_NORMAL | |
150 | }; | |
151 | ||
152 | /* Return number of classification appropriate for X. */ | |
153 | #define fpclassify(x) \ | |
154 | (sizeof (x) == sizeof (float) ? \ | |
63551311 | 155 | __fpclassifyf (x) \ |
377a515b | 156 | : sizeof (x) == sizeof (double) ? \ |
0d8733c4 | 157 | __fpclassify (x) : __fpclassifyl (x)) |
377a515b UD |
158 | |
159 | /* Return nonzero value if sign of X is negative. */ | |
160 | #define signbit(x) \ | |
161 | (sizeof (x) == sizeof (float) ? \ | |
162 | __signbitf (x) \ | |
163 | : sizeof (x) == sizeof (double) ? \ | |
164 | __signbit (x) : __signbitl (x)) | |
165 | ||
166 | /* Return nonzero value if X is not +-Inf or NaN. */ | |
63551311 UD |
167 | #define isfinite(x) \ |
168 | (sizeof (x) == sizeof (float) ? \ | |
169 | __finitef (x) \ | |
170 | : sizeof (x) == sizeof (double) ? \ | |
171 | __finite (x) : __finitel (x)) | |
377a515b UD |
172 | |
173 | /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ | |
174 | #define isnormal(x) (fpclassify (x) == FP_NORMAL) | |
175 | ||
176 | /* Return nonzero value if X is a NaN. We could use `fpclassify' but | |
177 | we already have this functions `__isnan' and it is faster. */ | |
178 | #define isnan(x) \ | |
179 | (sizeof (x) == sizeof (float) ? \ | |
180 | __isnanf (x) \ | |
181 | : sizeof (x) == sizeof (double) ? \ | |
182 | __isnan (x) : __isnanl (x)) | |
28f540f4 | 183 | |
28f540f4 | 184 | |
377a515b UD |
185 | /* Conversion functions. */ |
186 | ||
187 | /* Round X to nearest integral value according to current rounding | |
188 | direction. */ | |
c131718c UD |
189 | extern long int rinttol __P ((long double __x)); |
190 | extern long long int rinttoll __P ((long double __x)); | |
377a515b UD |
191 | |
192 | /* Round X to nearest integral value, rounding halfway cases away from | |
193 | zero. */ | |
c131718c UD |
194 | extern long int roundtol __P ((long double __x)); |
195 | extern long long int roundtoll __P ((long double __x)); | |
377a515b UD |
196 | |
197 | ||
198 | /* Comparison macros. */ | |
199 | ||
200 | /* Return nonzero value if X is greater than Y. */ | |
201 | #define isgreater(x, y) (!isunordered ((x), (y)) && (x) > (y)) | |
202 | ||
203 | /* Return nonzero value if X is greater than or equal to Y. */ | |
204 | #define isgreaterequal(x, y) (!isunordered ((x), (y)) && (x) >= (y)) | |
205 | ||
206 | /* Return nonzero value if X is less than Y. */ | |
207 | #define isless(x, y) (!isunordered ((x), (y)) && (x) < (y)) | |
208 | ||
209 | /* Return nonzero value if X is less than or equal to Y. */ | |
210 | #define islessequal(x, y) (!isunordered ((x), (y)) && (x) <= (y)) | |
211 | ||
212 | /* Return nonzero value if either X is less than Y or Y is less than X. */ | |
213 | #define islessgreater(x, y) \ | |
214 | (!isunordered ((x), (y)) && ((x) < (y) || (y) < (x))) | |
215 | ||
216 | /* Return nonzero value if arguments are unordered. */ | |
217 | #define isunordered(x, y) \ | |
218 | (fpclassify (x) == FP_NAN || fpclassify (y) == FP_NAN) | |
219 | ||
220 | #endif /* Use ISO C 9X. */ | |
221 | ||
28f540f4 | 222 | #ifdef __USE_MISC |
f7eac6eb | 223 | /* Support for various different standard error handling behaviors. */ |
28f540f4 | 224 | |
f7eac6eb | 225 | typedef enum { _IEEE_ = -1, _SVID_, _XOPEN_, _POSIX_ } _LIB_VERSION_TYPE; |
28f540f4 | 226 | |
f7eac6eb RM |
227 | /* This variable can be changed at run-time to any of the values above to |
228 | affect floating point error handling behavior (it may also be necessary | |
229 | to change the hardware FPU exception settings). */ | |
230 | extern _LIB_VERSION_TYPE _LIB_VERSION; | |
28f540f4 RM |
231 | #endif |
232 | ||
233 | ||
ceb2d9aa | 234 | #ifdef __USE_SVID |
f7eac6eb | 235 | /* In SVID error handling, `matherr' is called with this description |
2f6d1f1b UD |
236 | of the exceptional condition. |
237 | ||
238 | We have a problem when using C++ since `exception' is reserved in | |
239 | C++. */ | |
ceb2d9aa UD |
240 | #ifdef __cplusplus |
241 | struct __exception | |
242 | #else | |
f7eac6eb | 243 | struct exception |
ceb2d9aa | 244 | #endif |
f7eac6eb RM |
245 | { |
246 | int type; | |
247 | char *name; | |
248 | double arg1; | |
249 | double arg2; | |
250 | double retval; | |
251 | }; | |
28f540f4 | 252 | |
ceb2d9aa UD |
253 | #ifdef __cplusplus |
254 | extern int __matherr __P ((struct __exception *)); | |
255 | extern int matherr __P ((struct __exception *)); | |
256 | #else | |
23396375 | 257 | extern int __matherr __P ((struct exception *)); |
f7eac6eb | 258 | extern int matherr __P ((struct exception *)); |
ceb2d9aa | 259 | #endif |
28f540f4 | 260 | |
f7eac6eb | 261 | #define X_TLOSS 1.41484755040568800000e+16 |
28f540f4 | 262 | |
f7eac6eb RM |
263 | /* Types of exceptions in the `type' field. */ |
264 | #define DOMAIN 1 | |
265 | #define SING 2 | |
266 | #define OVERFLOW 3 | |
267 | #define UNDERFLOW 4 | |
268 | #define TLOSS 5 | |
269 | #define PLOSS 6 | |
28f540f4 | 270 | |
f7eac6eb RM |
271 | /* SVID mode specifies returning this large value instead of infinity. */ |
272 | #define HUGE FLT_MAX | |
273 | #include <float.h> /* Defines FLT_MAX. */ | |
28f540f4 | 274 | |
377a515b UD |
275 | #else /* !SVID */ |
276 | ||
277 | #ifdef __USE_XOPEN | |
278 | /* X/Open wants another strange constant. */ | |
279 | #define MAXFLOAT FLT_MAX | |
280 | #include <float.h> | |
281 | #endif | |
282 | ||
ceb2d9aa | 283 | #endif /* SVID */ |
28f540f4 | 284 | |
28f540f4 | 285 | |
28f540f4 | 286 | #ifdef __USE_BSD |
710f7bab | 287 | |
28f540f4 | 288 | /* Some useful constants. */ |
710f7bab RM |
289 | #define M_E _Mldbl(2.7182818284590452354) /* e */ |
290 | #define M_LOG2E _Mldbl(1.4426950408889634074) /* log 2e */ | |
291 | #define M_LOG10E _Mldbl(0.43429448190325182765) /* log 10e */ | |
292 | #define M_LN2 _Mldbl(0.69314718055994530942) /* log e2 */ | |
293 | #define M_LN10 _Mldbl(2.30258509299404568402) /* log e10 */ | |
294 | #define M_PI _Mldbl(3.14159265358979323846) /* pi */ | |
295 | #define M_PI_2 _Mldbl(1.57079632679489661923) /* pi/2 */ | |
296 | #define M_PI_4 _Mldbl(0.78539816339744830962) /* pi/4 */ | |
297 | #define M_1_PI _Mldbl(0.31830988618379067154) /* 1/pi */ | |
298 | #define M_2_PI _Mldbl(0.63661977236758134308) /* 2/pi */ | |
299 | #define M_2_SQRTPI _Mldbl(1.12837916709551257390) /* 2/sqrt(pi) */ | |
300 | #define M_SQRT2 _Mldbl(1.41421356237309504880) /* sqrt(2) */ | |
301 | #define M_SQRT1_2 _Mldbl(0.70710678118654752440) /* 1/sqrt(2) */ | |
302 | ||
303 | /* Our constants might specify more precision than `double' can represent. | |
304 | Use `long double' constants in standard and GNU C, where they are | |
305 | supported and the cast to `double'. */ | |
306 | #if __STDC__ - 0 || __GNUC__ - 0 | |
307 | #define _Mldbl(x) x##L | |
308 | #else /* Traditional C. */ | |
309 | #define _Mldbl(x) x | |
310 | #endif /* Standard or GNU C. */ | |
311 | ||
28f540f4 RM |
312 | #endif |
313 | ||
314 | ||
4d585333 | 315 | /* Get machine-dependent inline versions (if there are any). */ |
377a515b UD |
316 | #if (!defined __NO_MATH_INLINES && defined __OPTIMIZE__) \ |
317 | || defined __LIBC_M81_MATH_INLINES | |
4d585333 RM |
318 | #include <__math.h> |
319 | #endif | |
320 | ||
321 | ||
322 | __END_DECLS | |
323 | ||
324 | ||
28f540f4 | 325 | #endif /* math.h */ |