]>
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) |
f7eac6eb RM |
51 | #define __MATHDECL_1(type, function,suffix, args) \ |
52 | extern type __MATH_PRECNAME(function,suffix) args | |
53 | ||
54 | #define _Mdouble_ double | |
377a515b | 55 | #define __MATH_PRECNAME(name,r) __CONCAT(name,r) |
f7eac6eb RM |
56 | #include <mathcalls.h> |
57 | #undef _Mdouble_ | |
58 | #undef __MATH_PRECNAME | |
59 | ||
377a515b | 60 | #if defined __USE_MISC || defined __USE_ISOC9X |
76060ec0 | 61 | |
999493cb RM |
62 | |
63 | /* Include the file of declarations again, this time using `float' | |
f7eac6eb RM |
64 | instead of `double' and appending f to each function name. */ |
65 | ||
999493cb RM |
66 | #ifndef _Mfloat_ |
67 | #define _Mfloat_ float | |
68 | #endif | |
69 | #define _Mdouble_ _Mfloat_ | |
377a515b | 70 | #ifdef __STDC__ |
f7eac6eb | 71 | #define __MATH_PRECNAME(name,r) name##f##r |
377a515b UD |
72 | #else |
73 | #define __MATH_PRECNAME(name,r) name/**/f/**/r | |
74 | #endif | |
f7eac6eb RM |
75 | #include <mathcalls.h> |
76 | #undef _Mdouble_ | |
77 | #undef __MATH_PRECNAME | |
76060ec0 | 78 | |
377a515b | 79 | #if __STDC__ - 0 || __GNUC__ - 0 |
999493cb | 80 | /* Include the file of declarations again, this time using `long double' |
76060ec0 RM |
81 | instead of `double' and appending l to each function name. */ |
82 | ||
999493cb RM |
83 | #ifndef _Mlong_double_ |
84 | #define _Mlong_double_ long double | |
85 | #endif | |
86 | #define _Mdouble_ _Mlong_double_ | |
377a515b | 87 | #ifdef __STDC__ |
76060ec0 | 88 | #define __MATH_PRECNAME(name,r) name##l##r |
377a515b UD |
89 | #else |
90 | #define __MATH_PRECNAME(name,r) name/**/l/**/r | |
91 | #endif | |
76060ec0 RM |
92 | #include <mathcalls.h> |
93 | #undef _Mdouble_ | |
94 | #undef __MATH_PRECNAME | |
95 | ||
377a515b UD |
96 | #endif /* __STDC__ || __GNUC__ */ |
97 | ||
98 | #endif /* Use misc or ISO C 9X. */ | |
4cca6b86 UD |
99 | #undef __MATHDECL_1 |
100 | #undef __MATHDECL | |
101 | #undef __MATHCALL | |
102 | ||
103 | ||
104 | #if defined __USE_MISC || defined __USE_XOPEN || defined __USE_ISOC9X | |
105 | /* This variable is used by `gamma' and `lgamma'. */ | |
106 | extern int signgam; | |
107 | #endif | |
377a515b UD |
108 | |
109 | ||
110 | /* ISO C 9X defines some generic macros which work on any data type. */ | |
111 | #if __USE_ISOC9X | |
112 | ||
113 | /* All floating-point numbers can be put in one of these categories. */ | |
114 | enum | |
115 | { | |
116 | FP_NAN, | |
117 | #define FP_NAN FP_NAN | |
118 | FP_INFINITE, | |
119 | #define FP_INFINITE FP_INFINITE | |
120 | FP_ZERO, | |
121 | #define FP_ZERO FP_ZERO | |
122 | FP_SUBNORMAL, | |
123 | #define FP_SUBNORMAL FP_SUBNORMAL | |
124 | FP_NORMAL | |
125 | #define FP_NORMAL FP_NORMAL | |
126 | }; | |
127 | ||
128 | /* Return number of classification appropriate for X. */ | |
129 | #define fpclassify(x) \ | |
130 | (sizeof (x) == sizeof (float) ? \ | |
0d8733c4 | 131 | __fpclassifyf (x) \ |
377a515b | 132 | : sizeof (x) == sizeof (double) ? \ |
0d8733c4 | 133 | __fpclassify (x) : __fpclassifyl (x)) |
377a515b UD |
134 | |
135 | /* Return nonzero value if sign of X is negative. */ | |
136 | #define signbit(x) \ | |
137 | (sizeof (x) == sizeof (float) ? \ | |
138 | __signbitf (x) \ | |
139 | : sizeof (x) == sizeof (double) ? \ | |
140 | __signbit (x) : __signbitl (x)) | |
141 | ||
142 | /* Return nonzero value if X is not +-Inf or NaN. */ | |
143 | #define isfinite(x) (fpclassify (x) >= FP_ZERO) | |
144 | ||
145 | /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ | |
146 | #define isnormal(x) (fpclassify (x) == FP_NORMAL) | |
147 | ||
148 | /* Return nonzero value if X is a NaN. We could use `fpclassify' but | |
149 | we already have this functions `__isnan' and it is faster. */ | |
150 | #define isnan(x) \ | |
151 | (sizeof (x) == sizeof (float) ? \ | |
152 | __isnanf (x) \ | |
153 | : sizeof (x) == sizeof (double) ? \ | |
154 | __isnan (x) : __isnanl (x)) | |
28f540f4 | 155 | |
28f540f4 | 156 | |
377a515b UD |
157 | /* Conversion functions. */ |
158 | ||
159 | /* Round X to nearest integral value according to current rounding | |
160 | direction. */ | |
161 | extern long int rinttol __P ((double __x)); | |
162 | extern long long int rinttoll __P ((double __x)); | |
163 | ||
164 | /* Round X to nearest integral value, rounding halfway cases away from | |
165 | zero. */ | |
166 | extern long int roundtol __P ((double __x)); | |
167 | extern long long int roundtoll __P ((double __x)); | |
168 | ||
169 | ||
170 | /* Comparison macros. */ | |
171 | ||
172 | /* Return nonzero value if X is greater than Y. */ | |
173 | #define isgreater(x, y) (!isunordered ((x), (y)) && (x) > (y)) | |
174 | ||
175 | /* Return nonzero value if X is greater than or equal to Y. */ | |
176 | #define isgreaterequal(x, y) (!isunordered ((x), (y)) && (x) >= (y)) | |
177 | ||
178 | /* Return nonzero value if X is less than Y. */ | |
179 | #define isless(x, y) (!isunordered ((x), (y)) && (x) < (y)) | |
180 | ||
181 | /* Return nonzero value if X is less than or equal to Y. */ | |
182 | #define islessequal(x, y) (!isunordered ((x), (y)) && (x) <= (y)) | |
183 | ||
184 | /* Return nonzero value if either X is less than Y or Y is less than X. */ | |
185 | #define islessgreater(x, y) \ | |
186 | (!isunordered ((x), (y)) && ((x) < (y) || (y) < (x))) | |
187 | ||
188 | /* Return nonzero value if arguments are unordered. */ | |
189 | #define isunordered(x, y) \ | |
190 | (fpclassify (x) == FP_NAN || fpclassify (y) == FP_NAN) | |
191 | ||
192 | #endif /* Use ISO C 9X. */ | |
193 | ||
28f540f4 | 194 | #ifdef __USE_MISC |
f7eac6eb | 195 | /* Support for various different standard error handling behaviors. */ |
28f540f4 | 196 | |
f7eac6eb | 197 | typedef enum { _IEEE_ = -1, _SVID_, _XOPEN_, _POSIX_ } _LIB_VERSION_TYPE; |
28f540f4 | 198 | |
f7eac6eb RM |
199 | /* This variable can be changed at run-time to any of the values above to |
200 | affect floating point error handling behavior (it may also be necessary | |
201 | to change the hardware FPU exception settings). */ | |
202 | extern _LIB_VERSION_TYPE _LIB_VERSION; | |
28f540f4 RM |
203 | #endif |
204 | ||
205 | ||
ceb2d9aa | 206 | #ifdef __USE_SVID |
f7eac6eb | 207 | /* In SVID error handling, `matherr' is called with this description |
2f6d1f1b UD |
208 | of the exceptional condition. |
209 | ||
210 | We have a problem when using C++ since `exception' is reserved in | |
211 | C++. */ | |
ceb2d9aa UD |
212 | #ifdef __cplusplus |
213 | struct __exception | |
214 | #else | |
f7eac6eb | 215 | struct exception |
ceb2d9aa | 216 | #endif |
f7eac6eb RM |
217 | { |
218 | int type; | |
219 | char *name; | |
220 | double arg1; | |
221 | double arg2; | |
222 | double retval; | |
223 | }; | |
28f540f4 | 224 | |
ceb2d9aa UD |
225 | #ifdef __cplusplus |
226 | extern int __matherr __P ((struct __exception *)); | |
227 | extern int matherr __P ((struct __exception *)); | |
228 | #else | |
23396375 | 229 | extern int __matherr __P ((struct exception *)); |
f7eac6eb | 230 | extern int matherr __P ((struct exception *)); |
ceb2d9aa | 231 | #endif |
28f540f4 | 232 | |
f7eac6eb | 233 | #define X_TLOSS 1.41484755040568800000e+16 |
28f540f4 | 234 | |
f7eac6eb RM |
235 | /* Types of exceptions in the `type' field. */ |
236 | #define DOMAIN 1 | |
237 | #define SING 2 | |
238 | #define OVERFLOW 3 | |
239 | #define UNDERFLOW 4 | |
240 | #define TLOSS 5 | |
241 | #define PLOSS 6 | |
28f540f4 | 242 | |
f7eac6eb RM |
243 | /* SVID mode specifies returning this large value instead of infinity. */ |
244 | #define HUGE FLT_MAX | |
245 | #include <float.h> /* Defines FLT_MAX. */ | |
28f540f4 | 246 | |
377a515b UD |
247 | #else /* !SVID */ |
248 | ||
249 | #ifdef __USE_XOPEN | |
250 | /* X/Open wants another strange constant. */ | |
251 | #define MAXFLOAT FLT_MAX | |
252 | #include <float.h> | |
253 | #endif | |
254 | ||
ceb2d9aa | 255 | #endif /* SVID */ |
28f540f4 | 256 | |
28f540f4 | 257 | |
28f540f4 | 258 | #ifdef __USE_BSD |
710f7bab | 259 | |
28f540f4 | 260 | /* Some useful constants. */ |
710f7bab RM |
261 | #define M_E _Mldbl(2.7182818284590452354) /* e */ |
262 | #define M_LOG2E _Mldbl(1.4426950408889634074) /* log 2e */ | |
263 | #define M_LOG10E _Mldbl(0.43429448190325182765) /* log 10e */ | |
264 | #define M_LN2 _Mldbl(0.69314718055994530942) /* log e2 */ | |
265 | #define M_LN10 _Mldbl(2.30258509299404568402) /* log e10 */ | |
266 | #define M_PI _Mldbl(3.14159265358979323846) /* pi */ | |
267 | #define M_PI_2 _Mldbl(1.57079632679489661923) /* pi/2 */ | |
268 | #define M_PI_4 _Mldbl(0.78539816339744830962) /* pi/4 */ | |
269 | #define M_1_PI _Mldbl(0.31830988618379067154) /* 1/pi */ | |
270 | #define M_2_PI _Mldbl(0.63661977236758134308) /* 2/pi */ | |
271 | #define M_2_SQRTPI _Mldbl(1.12837916709551257390) /* 2/sqrt(pi) */ | |
272 | #define M_SQRT2 _Mldbl(1.41421356237309504880) /* sqrt(2) */ | |
273 | #define M_SQRT1_2 _Mldbl(0.70710678118654752440) /* 1/sqrt(2) */ | |
274 | ||
275 | /* Our constants might specify more precision than `double' can represent. | |
276 | Use `long double' constants in standard and GNU C, where they are | |
277 | supported and the cast to `double'. */ | |
278 | #if __STDC__ - 0 || __GNUC__ - 0 | |
279 | #define _Mldbl(x) x##L | |
280 | #else /* Traditional C. */ | |
281 | #define _Mldbl(x) x | |
282 | #endif /* Standard or GNU C. */ | |
283 | ||
28f540f4 RM |
284 | #endif |
285 | ||
286 | ||
4d585333 | 287 | /* Get machine-dependent inline versions (if there are any). */ |
377a515b UD |
288 | #if (!defined __NO_MATH_INLINES && defined __OPTIMIZE__) \ |
289 | || defined __LIBC_M81_MATH_INLINES | |
4d585333 RM |
290 | #include <__math.h> |
291 | #endif | |
292 | ||
293 | ||
294 | __END_DECLS | |
295 | ||
296 | ||
28f540f4 | 297 | #endif /* math.h */ |