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