fm/ipmitopo: fix 64-bit compilation
[unleashed.git] / include / math.h
blob78716f1a7debc7de361a3a660b502eab63c0c40c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #ifndef _MATH_H
30 #define _MATH_H
32 #include <iso/math_iso.h>
33 #include <iso/math_c99.h>
35 #if __cplusplus >= 199711L
36 using std::abs;
37 using std::acos;
38 using std::asin;
39 using std::atan2;
40 using std::atan;
41 using std::ceil;
42 using std::cos;
43 using std::cosh;
44 using std::exp;
45 using std::fabs;
46 using std::floor;
47 using std::fmod;
48 using std::frexp;
49 using std::ldexp;
50 using std::log10;
51 using std::log;
52 using std::modf;
53 using std::pow;
54 using std::sin;
55 using std::sinh;
56 using std::sqrt;
57 using std::tan;
58 using std::tanh;
59 #endif
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 #if defined(__cplusplus)
66 #define exception __math_exception
67 #endif
69 #ifndef __P
70 #ifdef __STDC__
71 #define __P(p) p
72 #else
73 #define __P(p) ()
74 #endif
75 #endif /* !defined(__P) */
77 #ifdef __GNUC__
78 #define HUGE_VAL (__builtin_huge_val())
79 #endif
81 #if defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || \
82 !defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)
84 * SVID & X/Open
86 #define M_E 2.7182818284590452354
87 #define M_LOG2E 1.4426950408889634074
88 #define M_LOG10E 0.43429448190325182765
89 #define M_LN2 0.69314718055994530942
90 #define M_LN10 2.30258509299404568402
91 #define M_PI 3.14159265358979323846
92 #define M_PI_2 1.57079632679489661923
93 #define M_PI_4 0.78539816339744830962
94 #define M_1_PI 0.31830988618379067154
95 #define M_2_PI 0.63661977236758134308
96 #define M_2_SQRTPI 1.12837916709551257390
97 #define M_SQRT2 1.41421356237309504880
98 #define M_SQRT1_2 0.70710678118654752440
100 extern int signgam;
102 #define MAXFLOAT ((float)3.40282346638528860e+38)
104 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
106 * SVID
108 enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi};
110 #ifdef __STDC__
111 extern const enum version _lib_version;
112 #else
113 extern enum version _lib_version;
114 #endif
116 struct exception {
117 int type;
118 char *name;
119 double arg1;
120 double arg2;
121 double retval;
124 #define HUGE MAXFLOAT
126 #define _ABS(x) ((x) < 0 ? -(x) : (x))
128 #define _REDUCE(TYPE, X, XN, C1, C2) { \
129 double x1 = (double)(TYPE)X, x2 = X - x1; \
130 X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); }
132 #define DOMAIN 1
133 #define SING 2
134 #define OVERFLOW 3
135 #define UNDERFLOW 4
136 #define TLOSS 5
137 #define PLOSS 6
139 #define _POLY1(x, c) ((c)[0] * (x) + (c)[1])
140 #define _POLY2(x, c) (_POLY1((x), (c)) * (x) + (c)[2])
141 #define _POLY3(x, c) (_POLY2((x), (c)) * (x) + (c)[3])
142 #define _POLY4(x, c) (_POLY3((x), (c)) * (x) + (c)[4])
143 #define _POLY5(x, c) (_POLY4((x), (c)) * (x) + (c)[5])
144 #define _POLY6(x, c) (_POLY5((x), (c)) * (x) + (c)[6])
145 #define _POLY7(x, c) (_POLY6((x), (c)) * (x) + (c)[7])
146 #define _POLY8(x, c) (_POLY7((x), (c)) * (x) + (c)[8])
147 #define _POLY9(x, c) (_POLY8((x), (c)) * (x) + (c)[9])
148 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */
151 * SVID & X/Open
153 /* BEGIN adopted by C99 */
154 extern double erf __P((double));
155 extern double erfc __P((double));
156 extern double hypot __P((double, double));
157 extern double lgamma __P((double));
159 #if defined(__MATHERR_ERRNO_DONTCARE)
160 #pragma does_not_read_global_data(erf, erfc, hypot)
161 #pragma does_not_write_global_data(erf, erfc, hypot)
162 #pragma no_side_effect(erf, erfc, hypot)
163 #endif
165 #if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__)
166 extern int isnan __P((double));
168 #pragma does_not_read_global_data(isnan)
169 #pragma does_not_write_global_data(isnan)
170 #pragma no_side_effect(isnan)
171 #endif
172 /* END adopted by C99 */
174 #if defined(__EXTENSIONS__) || _XOPEN_SOURCE - 0 < 600
175 extern double gamma __P((double)); /* deprecated; use lgamma */
176 #endif
177 extern double j0 __P((double));
178 extern double j1 __P((double));
179 extern double jn __P((int, double));
180 extern double y0 __P((double));
181 extern double y1 __P((double));
182 extern double yn __P((int, double));
184 #if defined(__MATHERR_ERRNO_DONTCARE)
185 #pragma does_not_read_global_data(j0, j1, jn, y0, y1, yn)
186 #pragma does_not_write_global_data(j0, j1, jn, y0, y1, yn)
187 #pragma no_side_effect(j0, j1, jn, y0, y1, yn)
188 #endif
189 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || \
190 _XOPEN_SOURCE - 0 >= 500 || \
191 defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1
193 * SVID & XPG 4.2/5
195 extern double scalb __P((double, double));
197 #if defined(__MATHERR_ERRNO_DONTCARE)
198 #pragma does_not_read_global_data(scalb)
199 #pragma does_not_write_global_data(scalb)
200 #pragma no_side_effect(scalb)
201 #endif
203 /* BEGIN adopted by C99 */
204 extern double acosh __P((double));
205 extern double asinh __P((double));
206 extern double atanh __P((double));
207 extern double cbrt __P((double));
208 extern double logb __P((double));
209 extern double nextafter __P((double, double));
210 extern double remainder __P((double, double));
213 * XPG 4.2/5
215 extern double expm1 __P((double));
216 extern int ilogb __P((double));
217 extern double log1p __P((double));
218 extern double rint __P((double));
220 #if defined(__MATHERR_ERRNO_DONTCARE)
221 #pragma does_not_read_global_data(acosh, asinh, atanh, cbrt)
222 #pragma does_not_read_global_data(logb, nextafter, remainder)
223 #pragma does_not_read_global_data(expm1, ilogb, log1p, rint)
224 #pragma does_not_write_global_data(acosh, asinh, atanh, cbrt)
225 #pragma does_not_write_global_data(logb, nextafter, remainder)
226 #pragma does_not_write_global_data(expm1, ilogb, log1p, rint)
227 #pragma no_side_effect(acosh, asinh, atanh, cbrt)
228 #pragma no_side_effect(logb, nextafter, remainder)
229 #pragma no_side_effect(expm1, ilogb, log1p, rint)
230 #endif
231 /* END adopted by C99 */
232 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || ... */
234 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
236 * SVID
238 extern int matherr __P((struct exception *));
241 * IEEE Test Vector
243 extern double significand __P((double));
245 #if defined(__MATHERR_ERRNO_DONTCARE)
246 #pragma does_not_read_global_data(significand)
247 #pragma does_not_write_global_data(significand)
248 #pragma no_side_effect(significand)
249 #endif
251 extern int signgamf; /* deprecated; use signgam */
252 extern int signgaml; /* deprecated; use signgam */
254 extern int isnanf __P((float));
255 extern int isnanl __P((long double));
256 extern float gammaf __P((float)); /* deprecated; use lgammaf */
257 extern float gammaf_r __P((float, int *)); /* deprecated; use lgammaf_r */
258 extern float j0f __P((float));
259 extern float j1f __P((float));
260 extern float jnf __P((int, float));
261 extern float lgammaf_r __P((float, int *));
262 extern float scalbf __P((float, float));
263 extern float significandf __P((float));
264 extern float y0f __P((float));
265 extern float y1f __P((float));
266 extern float ynf __P((int, float));
267 extern long double gammal __P((long double)); /* deprecated; use lgammal */
268 extern long double gammal_r __P((long double, int *)); /* deprecated */
269 extern long double j0l __P((long double));
270 extern long double j1l __P((long double));
271 extern long double jnl __P((int, long double));
272 extern long double lgammal_r __P((long double, int *));
273 extern long double scalbl __P((long double, long double));
274 extern long double significandl __P((long double));
275 extern long double y0l __P((long double));
276 extern long double y1l __P((long double));
277 extern long double ynl __P((int, long double));
279 #if defined(__MATHERR_ERRNO_DONTCARE)
280 #pragma does_not_read_global_data(isnanf, isnanl)
281 #pragma does_not_write_global_data(isnanf, isnanl)
282 #pragma no_side_effect(isnanf, isnanl)
283 #pragma does_not_read_global_data(gammaf_r, j0f, j1f, jnf, lgammaf_r, scalbf)
284 #pragma does_not_read_global_data(significandf, y0f, y1f, ynf)
285 #pragma does_not_write_global_data(j0f, j1f, jnf, scalbf)
286 #pragma does_not_write_global_data(significandf, y0f, y1f, ynf)
287 #pragma no_side_effect(j0f, j1f, jnf, scalbf)
288 #pragma no_side_effect(significandf, y0f, y1f, ynf)
289 #pragma does_not_read_global_data(gammal_r, j0l, j1l, jnl, lgammal_r, scalbl)
290 #pragma does_not_read_global_data(significandl, y0l, y1l, ynl)
291 #pragma does_not_write_global_data(j0l, j1l, jnl, scalbl)
292 #pragma does_not_write_global_data(significandl, y0l, y1l, ynl)
293 #pragma no_side_effect(j0l, j1l, jnl, scalbl)
294 #pragma no_side_effect(significandl, y0l, y1l, ynl)
295 #endif
298 * for sin+cos->sincos transformation
300 extern void sincos __P((double, double *, double *));
301 extern void sincosf __P((float, float *, float *));
302 extern void sincosl __P((long double, long double *, long double *));
304 #if defined(__MATHERR_ERRNO_DONTCARE)
305 #pragma does_not_read_global_data(sincos, sincosf, sincosl)
306 #endif
308 /* BEGIN adopted by C99 */
310 * Functions callable from C, intended to support IEEE arithmetic.
312 extern double copysign __P((double, double));
313 extern double scalbn __P((double, int));
315 #if defined(__MATHERR_ERRNO_DONTCARE)
316 #pragma does_not_read_global_data(copysign, scalbn)
317 #pragma does_not_write_global_data(copysign, scalbn)
318 #pragma no_side_effect(copysign, scalbn)
319 #endif
320 /* END adopted by C99 */
323 * Reentrant version of gamma & lgamma; passes signgam back by reference
324 * as the second argument; user must allocate space for signgam.
326 extern double gamma_r __P((double, int *)); /* deprecated; use lgamma_r */
327 extern double lgamma_r __P((double, int *));
329 #if defined(__MATHERR_ERRNO_DONTCARE)
330 #pragma does_not_read_global_data(gamma_r, lgamma_r)
331 #endif
333 /* BEGIN adopted by C99 */
334 extern float modff __P((float, float *));
336 #if defined(__MATHERR_ERRNO_DONTCARE)
337 #pragma does_not_read_global_data(modff)
338 #endif
339 /* END adopted by C99 */
341 #if defined(__EXTENSIONS__) || !defined(__cplusplus)
342 #include <floatingpoint.h>
343 #endif
344 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */
345 #endif /* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || ... */
347 #if defined(__cplusplus) && defined(__GNUC__)
348 #undef exception
349 #endif
351 #ifdef __cplusplus
353 #endif
355 #endif /* _MATH_H */