]>
Commit | Line | Data |
---|---|---|
f7eac6eb | 1 | /* Declarations for math functions. |
0a614877 | 2 | Copyright (C) 1991, 92, 93, 95, 96, 97, 98 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 | |
28f540f4 | 25 | #define _MATH_H 1 |
5107cf1d | 26 | |
28f540f4 RM |
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. */ | |
5107cf1d | 33 | #include <bits/huge_val.h> |
28f540f4 RM |
34 | |
35 | /* Get machine-dependent NAN value (returned for some domain errors). */ | |
36 | #ifdef __USE_GNU | |
478b92f0 | 37 | # include <bits/nan.h> |
28f540f4 RM |
38 | #endif |
39 | ||
40 | ||
5107cf1d UD |
41 | /* The file <bits/mathcalls.h> contains the prototypes for all the |
42 | actual math functions. These macros are used for those prototypes, | |
43 | so we can easily declare each function as both `name' and `__name', | |
f7eac6eb RM |
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) |
5107cf1d | 61 | #include <bits/mathcalls.h> |
f7eac6eb RM |
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 | ||
fe0ec73e UD |
71 | # ifndef _Mfloat_ |
72 | # define _Mfloat_ float | |
478b92f0 | 73 | # endif |
fe0ec73e | 74 | # define _Mdouble_ _Mfloat_ |
478b92f0 | 75 | # ifdef __STDC__ |
fe0ec73e | 76 | # define __MATH_PRECNAME(name,r) name##f##r |
478b92f0 | 77 | # else |
fe0ec73e | 78 | # define __MATH_PRECNAME(name,r) name/**/f/**/r |
478b92f0 UD |
79 | # endif |
80 | # include <bits/mathcalls.h> | |
81 | # undef _Mdouble_ | |
82 | # undef __MATH_PRECNAME | |
76060ec0 | 83 | |
fe0ec73e UD |
84 | # if __STDC__ - 0 || __GNUC__ - 0 |
85 | /* Include the file of declarations again, this time using `long double' | |
86 | instead of `double' and appending l to each function name. */ | |
87 | ||
88 | # ifndef _Mlong_double_ | |
89 | # define _Mlong_double_ long double | |
90 | # endif | |
91 | # define _Mdouble_ _Mlong_double_ | |
92 | # ifdef __STDC__ | |
93 | # define __MATH_PRECNAME(name,r) name##l##r | |
94 | # else | |
95 | # define __MATH_PRECNAME(name,r) name/**/l/**/r | |
96 | # endif | |
97 | # include <bits/mathcalls.h> | |
98 | # undef _Mdouble_ | |
99 | # undef __MATH_PRECNAME | |
100 | ||
101 | # endif /* __STDC__ || __GNUC__ */ | |
377a515b UD |
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 | ||
fe0ec73e | 121 | float_t floating-point type at least as wide as `float' used |
63551311 | 122 | to evaluate `float' expressions |
fe0ec73e | 123 | double_t floating-point type at least as wide as `double' used |
63551311 UD |
124 | to evaluate `double' expressions |
125 | ||
fe0ec73e | 126 | FLT_EVAL_METHOD |
63551311 UD |
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 | ||
fe0ec73e | 133 | INFINITY representation of the infinity value of type `float' |
dfd2257a | 134 | |
fe0ec73e UD |
135 | FP_FAST_FMA |
136 | FP_FAST_FMAF | |
137 | FP_FAST_FMAL | |
dfd2257a UD |
138 | If defined it indicates that the the `fma' function |
139 | generally executes about as fast as a multiply and an add. | |
140 | This macro is defined only iff the `fma' function is | |
141 | implemented directly with a hardware multiply-add instructions. | |
142 | ||
143 | FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'. | |
144 | FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'. | |
145 | ||
fe0ec73e UD |
146 | DECIMAL_DIG Number of decimal digits supported by conversion between |
147 | decimal and all internal floating-point formats. | |
148 | ||
63551311 | 149 | */ |
478b92f0 | 150 | # include <bits/mathdef.h> |
63551311 | 151 | |
377a515b UD |
152 | /* All floating-point numbers can be put in one of these categories. */ |
153 | enum | |
154 | { | |
155 | FP_NAN, | |
478b92f0 | 156 | # define FP_NAN FP_NAN |
377a515b | 157 | FP_INFINITE, |
478b92f0 | 158 | # define FP_INFINITE FP_INFINITE |
377a515b | 159 | FP_ZERO, |
478b92f0 | 160 | # define FP_ZERO FP_ZERO |
377a515b | 161 | FP_SUBNORMAL, |
478b92f0 | 162 | # define FP_SUBNORMAL FP_SUBNORMAL |
377a515b | 163 | FP_NORMAL |
478b92f0 | 164 | # define FP_NORMAL FP_NORMAL |
377a515b UD |
165 | }; |
166 | ||
167 | /* Return number of classification appropriate for X. */ | |
478b92f0 | 168 | # define fpclassify(x) \ |
377a515b | 169 | (sizeof (x) == sizeof (float) ? \ |
63551311 | 170 | __fpclassifyf (x) \ |
377a515b | 171 | : sizeof (x) == sizeof (double) ? \ |
0d8733c4 | 172 | __fpclassify (x) : __fpclassifyl (x)) |
377a515b UD |
173 | |
174 | /* Return nonzero value if sign of X is negative. */ | |
478b92f0 | 175 | # define signbit(x) \ |
377a515b UD |
176 | (sizeof (x) == sizeof (float) ? \ |
177 | __signbitf (x) \ | |
178 | : sizeof (x) == sizeof (double) ? \ | |
179 | __signbit (x) : __signbitl (x)) | |
180 | ||
181 | /* Return nonzero value if X is not +-Inf or NaN. */ | |
478b92f0 | 182 | # define isfinite(x) \ |
63551311 UD |
183 | (sizeof (x) == sizeof (float) ? \ |
184 | __finitef (x) \ | |
185 | : sizeof (x) == sizeof (double) ? \ | |
186 | __finite (x) : __finitel (x)) | |
377a515b UD |
187 | |
188 | /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ | |
478b92f0 | 189 | # define isnormal(x) (fpclassify (x) == FP_NORMAL) |
377a515b UD |
190 | |
191 | /* Return nonzero value if X is a NaN. We could use `fpclassify' but | |
192 | we already have this functions `__isnan' and it is faster. */ | |
478b92f0 | 193 | # define isnan(x) \ |
377a515b UD |
194 | (sizeof (x) == sizeof (float) ? \ |
195 | __isnanf (x) \ | |
196 | : sizeof (x) == sizeof (double) ? \ | |
197 | __isnan (x) : __isnanl (x)) | |
28f540f4 | 198 | |
377a515b UD |
199 | #endif /* Use ISO C 9X. */ |
200 | ||
28f540f4 | 201 | #ifdef __USE_MISC |
f7eac6eb | 202 | /* Support for various different standard error handling behaviors. */ |
b9337b6a UD |
203 | typedef enum |
204 | { | |
205 | _IEEE_ = -1, /* According to IEEE 754/IEEE 854. */ | |
206 | _SVID_, /* According to System V, release 4. */ | |
207 | _XOPEN_, /* Nowadays also Unix98. */ | |
208 | _POSIX_, | |
209 | _ISOC_ /* Actually this is ISO C 9X. */ | |
210 | } _LIB_VERSION_TYPE; | |
28f540f4 | 211 | |
f7eac6eb RM |
212 | /* This variable can be changed at run-time to any of the values above to |
213 | affect floating point error handling behavior (it may also be necessary | |
214 | to change the hardware FPU exception settings). */ | |
215 | extern _LIB_VERSION_TYPE _LIB_VERSION; | |
28f540f4 RM |
216 | #endif |
217 | ||
218 | ||
ceb2d9aa | 219 | #ifdef __USE_SVID |
f7eac6eb | 220 | /* In SVID error handling, `matherr' is called with this description |
2f6d1f1b UD |
221 | of the exceptional condition. |
222 | ||
fe0ec73e UD |
223 | We have a problem when using C++ since `exception' is a reserved |
224 | name in C++. */ | |
478b92f0 | 225 | # ifdef __cplusplus |
ceb2d9aa | 226 | struct __exception |
478b92f0 | 227 | # else |
f7eac6eb | 228 | struct exception |
478b92f0 | 229 | # endif |
f7eac6eb RM |
230 | { |
231 | int type; | |
232 | char *name; | |
233 | double arg1; | |
234 | double arg2; | |
235 | double retval; | |
236 | }; | |
28f540f4 | 237 | |
478b92f0 UD |
238 | # ifdef __cplusplus |
239 | extern int __matherr __P ((struct __exception *__exc)); | |
240 | extern int matherr __P ((struct __exception *__exc)); | |
241 | # else | |
242 | extern int __matherr __P ((struct exception *__exc)); | |
243 | extern int matherr __P ((struct exception *__exc)); | |
244 | # endif | |
28f540f4 | 245 | |
478b92f0 | 246 | # define X_TLOSS 1.41484755040568800000e+16 |
28f540f4 | 247 | |
f7eac6eb | 248 | /* Types of exceptions in the `type' field. */ |
478b92f0 UD |
249 | # define DOMAIN 1 |
250 | # define SING 2 | |
251 | # define OVERFLOW 3 | |
252 | # define UNDERFLOW 4 | |
253 | # define TLOSS 5 | |
254 | # define PLOSS 6 | |
28f540f4 | 255 | |
f7eac6eb | 256 | /* SVID mode specifies returning this large value instead of infinity. */ |
478b92f0 UD |
257 | # define HUGE FLT_MAX |
258 | # include <float.h> /* Defines FLT_MAX. */ | |
28f540f4 | 259 | |
377a515b UD |
260 | #else /* !SVID */ |
261 | ||
478b92f0 | 262 | # ifdef __USE_XOPEN |
377a515b | 263 | /* X/Open wants another strange constant. */ |
478b92f0 UD |
264 | # define MAXFLOAT FLT_MAX |
265 | # include <float.h> | |
266 | # endif | |
377a515b | 267 | |
ceb2d9aa | 268 | #endif /* SVID */ |
28f540f4 | 269 | |
28f540f4 | 270 | |
28f540f4 | 271 | /* Some useful constants. */ |
0a614877 UD |
272 | #if defined __USE_BSD || defined __USE_UNIX98 |
273 | # define M_E 2.7182818284590452354 /* e */ | |
274 | # define M_LOG2E 1.4426950408889634074 /* log_2 e */ | |
275 | # define M_LOG10E 0.43429448190325182765 /* log_10 e */ | |
276 | # define M_LN2 0.69314718055994530942 /* log_e 2 */ | |
277 | # define M_LN10 2.30258509299404568402 /* log_e 10 */ | |
278 | # define M_PI 3.14159265358979323846 /* pi */ | |
279 | # define M_PI_2 1.57079632679489661923 /* pi/2 */ | |
280 | # define M_PI_4 0.78539816339744830962 /* pi/4 */ | |
281 | # define M_1_PI 0.31830988618379067154 /* 1/pi */ | |
282 | # define M_2_PI 0.63661977236758134308 /* 2/pi */ | |
283 | # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ | |
284 | # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |
285 | # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | |
714a562f UD |
286 | #endif |
287 | ||
0a614877 UD |
288 | /* The above constants are not adequate for computation using `long double's. |
289 | Therefore we provide as an extension constants with similar names as a | |
9a24f906 | 290 | GNU extension. Provide enough digits for the 128-bit IEEE quad. */ |
0a614877 | 291 | #ifdef __USE_GNU |
9a24f906 UD |
292 | # define M_El 2.7182818284590452353602874713526625L /* e */ |
293 | # define M_LOG2El 1.4426950408889634073599246810018922L /* log_2 e */ | |
294 | # define M_LOG10El 0.4342944819032518276511289189166051L /* log_10 e */ | |
295 | # define M_LN2l 0.6931471805599453094172321214581766L /* log_e 2 */ | |
296 | # define M_LN10l 2.3025850929940456840179914546843642L /* log_e 10 */ | |
297 | # define M_PIl 3.1415926535897932384626433832795029L /* pi */ | |
298 | # define M_PI_2l 1.5707963267948966192313216916397514L /* pi/2 */ | |
299 | # define M_PI_4l 0.7853981633974483096156608458198757L /* pi/4 */ | |
300 | # define M_1_PIl 0.3183098861837906715377675267450287L /* 1/pi */ | |
301 | # define M_2_PIl 0.6366197723675813430755350534900574L /* 2/pi */ | |
302 | # define M_2_SQRTPIl 1.1283791670955125738961589031215452L /* 2/sqrt(pi) */ | |
303 | # define M_SQRT2l 1.4142135623730950488016887242096981L /* sqrt(2) */ | |
304 | # define M_SQRT1_2l 0.7071067811865475244008443621048490L /* 1/sqrt(2) */ | |
0a614877 | 305 | #endif |
710f7bab | 306 | |
28f540f4 | 307 | |
4d585333 | 308 | /* Get machine-dependent inline versions (if there are any). */ |
907a1bac | 309 | #ifdef __OPTIMIZE__ |
478b92f0 | 310 | # include <bits/mathinline.h> |
4d585333 RM |
311 | #endif |
312 | ||
313 | ||
ae1025be UD |
314 | #if __USE_ISOC9X |
315 | /* ISO C 9X defines some macros to compare number while taking care | |
316 | for unordered numbers. Since many FPUs provide special | |
907a1bac UD |
317 | instructions to support these operations and these tests are |
318 | defined in <bits/mathinline.h>, we define the generic macros at | |
fe0ec73e | 319 | this late point and only if they are not defined yet. */ |
ae1025be UD |
320 | |
321 | /* Return nonzero value if X is greater than Y. */ | |
322 | # ifndef isgreater | |
55c14926 UD |
323 | # define isgreater(x, y) \ |
324 | (__extension__ \ | |
325 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
326 | !isunordered (__x, __y) && __x > __y; })) | |
ae1025be UD |
327 | # endif |
328 | ||
329 | /* Return nonzero value if X is greater than or equal to Y. */ | |
330 | # ifndef isgreaterequal | |
55c14926 UD |
331 | # define isgreaterequal(x, y) \ |
332 | (__extension__ \ | |
333 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
334 | !isunordered (__x, __y) && __x >= __y; })) | |
ae1025be UD |
335 | # endif |
336 | ||
337 | /* Return nonzero value if X is less than Y. */ | |
338 | # ifndef isless | |
55c14926 UD |
339 | # define isless(x, y) \ |
340 | (__extension__ \ | |
341 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
342 | !isunordered (__x, __y) && __x < __y; })) | |
ae1025be UD |
343 | # endif |
344 | ||
345 | /* Return nonzero value if X is less than or equal to Y. */ | |
346 | # ifndef islessequal | |
55c14926 UD |
347 | # define islessequal(x, y) \ |
348 | (__extension__ \ | |
349 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
350 | !isunordered (__x, __y) && __x <= __y; })) | |
ae1025be UD |
351 | # endif |
352 | ||
353 | /* Return nonzero value if either X is less than Y or Y is less than X. */ | |
354 | # ifndef islessgreater | |
355 | # define islessgreater(x, y) \ | |
55c14926 UD |
356 | (__extension__ \ |
357 | ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ | |
358 | !isunordered (__x, __y) && (__x < __y || __y < __x); })) | |
ae1025be UD |
359 | # endif |
360 | ||
361 | /* Return nonzero value if arguments are unordered. */ | |
362 | # ifndef isunordered | |
d111572f | 363 | # define isunordered(u, v) \ |
55c14926 | 364 | (__extension__ \ |
d111572f UD |
365 | ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \ |
366 | fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; })) | |
ae1025be UD |
367 | # endif |
368 | ||
369 | #endif | |
370 | ||
4d585333 RM |
371 | __END_DECLS |
372 | ||
373 | ||
28f540f4 | 374 | #endif /* math.h */ |