1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _MATH_H
27 #define	_MATH_H
28 
29 #include <iso/math_iso.h>
30 #include <iso/math_c99.h>
31 
32 #if __cplusplus >= 199711L
33 using std::abs;
34 using std::acos;
35 using std::asin;
36 using std::atan2;
37 using std::atan;
38 using std::ceil;
39 using std::cos;
40 using std::cosh;
41 using std::exp;
42 using std::fabs;
43 using std::floor;
44 using std::fmod;
45 using std::frexp;
46 using std::ldexp;
47 using std::log10;
48 using std::log;
49 using std::modf;
50 using std::pow;
51 using std::sin;
52 using std::sinh;
53 using std::sqrt;
54 using std::tan;
55 using std::tanh;
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #if defined(__cplusplus) && defined(__GNUC__)
63 #define	exception	__math_exception
64 #endif
65 
66 #ifndef __P
67 #ifdef __STDC__
68 #define	__P(p)	p
69 #else
70 #define	__P(p)	()
71 #endif
72 #endif	/* !defined(__P) */
73 
74 #if defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || \
75 	!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)
76 /*
77  * SVID & X/Open
78  */
79 #define	M_E		2.7182818284590452354
80 #define	M_LOG2E		1.4426950408889634074
81 #define	M_LOG10E	0.43429448190325182765
82 #define	M_LN2		0.69314718055994530942
83 #define	M_LN10		2.30258509299404568402
84 #define	M_PI		3.14159265358979323846
85 #define	M_PI_2		1.57079632679489661923
86 #define	M_PI_4		0.78539816339744830962
87 #define	M_1_PI		0.31830988618379067154
88 #define	M_2_PI		0.63661977236758134308
89 #define	M_2_SQRTPI	1.12837916709551257390
90 #define	M_SQRT2		1.41421356237309504880
91 #define	M_SQRT1_2	0.70710678118654752440
92 
93 extern int signgam;
94 
95 #define	MAXFLOAT	((float)3.40282346638528860e+38)
96 
97 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
98 /*
99  * SVID
100  */
101 enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi};
102 
103 #ifdef __STDC__
104 extern const enum version _lib_version;
105 #else
106 extern enum version _lib_version;
107 #endif
108 
109 struct exception {
110 	int type;
111 	char *name;
112 	double arg1;
113 	double arg2;
114 	double retval;
115 };
116 
117 #define	HUGE		MAXFLOAT
118 
119 #define	_ABS(x)		((x) < 0 ? -(x) : (x))
120 
121 #define	_REDUCE(TYPE, X, XN, C1, C2)	{ \
122 	double x1 = (double)(TYPE)X, x2 = X - x1; \
123 	X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); }
124 
125 #define	DOMAIN		1
126 #define	SING		2
127 #define	OVERFLOW	3
128 #define	UNDERFLOW	4
129 #define	TLOSS		5
130 #define	PLOSS		6
131 
132 #define	_POLY1(x, c)	((c)[0] * (x) + (c)[1])
133 #define	_POLY2(x, c)	(_POLY1((x), (c)) * (x) + (c)[2])
134 #define	_POLY3(x, c)	(_POLY2((x), (c)) * (x) + (c)[3])
135 #define	_POLY4(x, c)	(_POLY3((x), (c)) * (x) + (c)[4])
136 #define	_POLY5(x, c)	(_POLY4((x), (c)) * (x) + (c)[5])
137 #define	_POLY6(x, c)	(_POLY5((x), (c)) * (x) + (c)[6])
138 #define	_POLY7(x, c)	(_POLY6((x), (c)) * (x) + (c)[7])
139 #define	_POLY8(x, c)	(_POLY7((x), (c)) * (x) + (c)[8])
140 #define	_POLY9(x, c)	(_POLY8((x), (c)) * (x) + (c)[9])
141 #endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */
142 
143 /*
144  * SVID & X/Open
145  */
146 /* BEGIN adopted by C99 */
147 extern double erf __P((double));
148 extern double erfc __P((double));
149 extern double hypot __P((double, double));
150 extern double lgamma __P((double));
151 
152 #if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__)
153 extern int isnan __P((double));
154 #endif
155 /* END adopted by C99 */
156 
157 #if defined(__EXTENSIONS__) || _XOPEN_SOURCE - 0 < 600
158 extern double gamma __P((double));		/* deprecated; use lgamma */
159 #endif
160 extern double j0 __P((double));
161 extern double j1 __P((double));
162 extern double jn __P((int, double));
163 extern double y0 __P((double));
164 extern double y1 __P((double));
165 extern double yn __P((int, double));
166 
167 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || \
168 	_XOPEN_SOURCE - 0 >= 500 || \
169 	defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1
170 /*
171  * SVID & XPG 4.2/5
172  */
173 extern double scalb __P((double, double));
174 
175 /* BEGIN adopted by C99 */
176 extern double acosh __P((double));
177 extern double asinh __P((double));
178 extern double atanh __P((double));
179 extern double cbrt __P((double));
180 extern double logb __P((double));
181 extern double nextafter __P((double, double));
182 extern double remainder __P((double, double));
183 
184 /*
185  * XPG 4.2/5
186  */
187 extern double expm1 __P((double));
188 extern int ilogb __P((double));
189 extern double log1p __P((double));
190 extern double rint __P((double));
191 
192 /* END adopted by C99 */
193 #endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || ... */
194 
195 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
196 /*
197  * SVID
198  */
199 extern int matherr __P((struct exception *));
200 
201 /*
202  * IEEE Test Vector
203  */
204 extern double significand __P((double));
205 
206 extern int signgamf;				/* deprecated; use signgam */
207 extern int signgaml;				/* deprecated; use signgam */
208 
209 extern int isnanf __P((float));
210 extern int isnanl __P((long double));
211 extern float gammaf __P((float));		/* deprecated; use lgammaf */
212 extern float gammaf_r __P((float, int *));	/* deprecated; use lgammaf_r */
213 extern float j0f __P((float));
214 extern float j1f __P((float));
215 extern float jnf __P((int, float));
216 extern float lgammaf_r __P((float, int *));
217 extern float scalbf __P((float, float));
218 extern float significandf __P((float));
219 extern float y0f __P((float));
220 extern float y1f __P((float));
221 extern float ynf __P((int, float));
222 extern long double gammal __P((long double));	/* deprecated; use lgammal */
223 extern long double gammal_r __P((long double, int *));	/* deprecated */
224 extern long double j0l __P((long double));
225 extern long double j1l __P((long double));
226 extern long double jnl __P((int, long double));
227 extern long double lgammal_r __P((long double, int *));
228 extern long double scalbl __P((long double, long double));
229 extern long double significandl __P((long double));
230 extern long double y0l __P((long double));
231 extern long double y1l __P((long double));
232 extern long double ynl __P((int, long double));
233 
234 /*
235  * for sin+cos->sincos transformation
236  */
237 extern void sincos __P((double, double *, double *));
238 extern void sincosf __P((float, float *, float *));
239 extern void sincosl __P((long double, long double *, long double *));
240 
241 /* BEGIN adopted by C99 */
242 /*
243  * Functions callable from C, intended to support IEEE arithmetic.
244  */
245 extern double copysign __P((double, double));
246 extern double scalbn __P((double, int));
247 
248 /* END adopted by C99 */
249 
250 /*
251  * Reentrant version of gamma & lgamma; passes signgam back by reference
252  * as the second argument; user must allocate space for signgam.
253  */
254 extern double gamma_r __P((double, int *));	/* deprecated; use lgamma_r */
255 extern double lgamma_r __P((double, int *));
256 
257 /* BEGIN adopted by C99 */
258 extern float modff __P((float, float *));
259 /* END adopted by C99 */
260 
261 #if defined(__EXTENSIONS__) || !defined(__cplusplus)
262 #include <floatingpoint.h>
263 #endif
264 #endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */
265 #endif	/* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || ... */
266 
267 #if defined(__cplusplus) && defined(__GNUC__)
268 #undef	exception
269 #endif
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif	/* _MATH_H */
276