summaryrefslogtreecommitdiff
path: root/usr/src/head/math.h
blob: 3cf2d96571fdffec96662660bec381d3a365ee12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */
/*
 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
 */

#ifndef _MATH_H
#define	_MATH_H

#include <iso/math_iso.h>
#include <iso/math_c99.h>

#if __cplusplus >= 199711L
using std::abs;
using std::acos;
using std::asin;
using std::atan2;
using std::atan;
using std::ceil;
using std::cos;
using std::cosh;
using std::exp;
using std::fabs;
using std::floor;
using std::fmod;
using std::frexp;
using std::ldexp;
using std::log10;
using std::log;
using std::modf;
using std::pow;
using std::sin;
using std::sinh;
using std::sqrt;
using std::tan;
using std::tanh;
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined(__cplusplus)
#define	exception	__math_exception
#endif

#if defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || \
	!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)
/*
 * SVID & X/Open
 */
#define	M_E		2.7182818284590452354
#define	M_LOG2E		1.4426950408889634074
#define	M_LOG10E	0.43429448190325182765
#define	M_LN2		0.69314718055994530942
#define	M_LN10		2.30258509299404568402
#define	M_PI		3.14159265358979323846
#define	M_PI_2		1.57079632679489661923
#define	M_PI_4		0.78539816339744830962
#define	M_1_PI		0.31830988618379067154
#define	M_2_PI		0.63661977236758134308
#define	M_2_SQRTPI	1.12837916709551257390
#define	M_SQRT2		1.41421356237309504880
#define	M_SQRT1_2	0.70710678118654752440

extern int signgam;

#define	MAXFLOAT	((float)3.40282346638528860e+38)

#if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
/*
 * SVID
 */
enum version {libm_ieee = -1, c_issue_4, ansi_1, strict_ansi};

#ifdef __STDC__
extern const enum version _lib_version;
#else
extern enum version _lib_version;
#endif

struct exception {
	int type;
	char *name;
	double arg1;
	double arg2;
	double retval;
};

#define	HUGE		MAXFLOAT

#define	_ABS(x)		((x) < 0 ? -(x) : (x))

#define	_REDUCE(TYPE, X, XN, C1, C2)	{ \
	double x1 = (double)(TYPE)X, x2 = X - x1; \
	X = x1 - (XN) * (C1); X += x2; X -= (XN) * (C2); }

#define	DOMAIN		1
#define	SING		2
#define	OVERFLOW	3
#define	UNDERFLOW	4
#define	TLOSS		5
#define	PLOSS		6

#define	_POLY1(x, c)	((c)[0] * (x) + (c)[1])
#define	_POLY2(x, c)	(_POLY1((x), (c)) * (x) + (c)[2])
#define	_POLY3(x, c)	(_POLY2((x), (c)) * (x) + (c)[3])
#define	_POLY4(x, c)	(_POLY3((x), (c)) * (x) + (c)[4])
#define	_POLY5(x, c)	(_POLY4((x), (c)) * (x) + (c)[5])
#define	_POLY6(x, c)	(_POLY5((x), (c)) * (x) + (c)[6])
#define	_POLY7(x, c)	(_POLY6((x), (c)) * (x) + (c)[7])
#define	_POLY8(x, c)	(_POLY7((x), (c)) * (x) + (c)[8])
#define	_POLY9(x, c)	(_POLY8((x), (c)) * (x) + (c)[9])
#endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */

/*
 * SVID & X/Open
 */
/* BEGIN adopted by C99 */
extern double erf(double);
extern double erfc(double);
extern double hypot(double, double);
extern double lgamma(double);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(erf, erfc, hypot)
#pragma does_not_write_global_data(erf, erfc, hypot)
#pragma no_side_effect(erf, erfc, hypot)
#endif

#if !defined(_STDC_C99) && _XOPEN_SOURCE - 0 < 600 && !defined(__C99FEATURES__)
extern int isnan(double);

#pragma does_not_read_global_data(isnan)
#pragma does_not_write_global_data(isnan)
#pragma no_side_effect(isnan)
#endif
/* END adopted by C99 */

#if defined(__EXTENSIONS__) || _XOPEN_SOURCE - 0 < 600
extern double gamma(double);		/* deprecated; use lgamma */
#endif
extern double j0(double);
extern double j1(double);
extern double jn(int, double);
extern double y0(double);
extern double y1(double);
extern double yn(int, double);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(j0, j1, jn, y0, y1, yn)
#pragma does_not_write_global_data(j0, j1, jn, y0, y1, yn)
#pragma no_side_effect(j0, j1, jn, y0, y1, yn)
#endif
#if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || \
	_XOPEN_SOURCE - 0 >= 500 || \
	defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1
/*
 * SVID & XPG 4.2/5 - removed from XPG7.
 */
#if !defined(_STRICT_SYMBOLS) || !defined(_XPG7)
extern double scalb(double, double);
#endif

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(scalb)
#pragma does_not_write_global_data(scalb)
#pragma no_side_effect(scalb)
#endif

/* BEGIN adopted by C99 */
extern double acosh(double);
extern double asinh(double);
extern double atanh(double);
extern double cbrt(double);
extern double logb(double);
extern double nextafter(double, double);
extern double remainder(double, double);

/*
 * XPG 4.2/5
 */
extern double expm1(double);
extern int ilogb(double);
extern double log1p(double);
extern double rint(double);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(acosh, asinh, atanh, cbrt)
#pragma does_not_read_global_data(logb, nextafter, remainder)
#pragma does_not_read_global_data(expm1, ilogb, log1p, rint)
#pragma does_not_write_global_data(acosh, asinh, atanh, cbrt)
#pragma does_not_write_global_data(logb, nextafter, remainder)
#pragma does_not_write_global_data(expm1, ilogb, log1p, rint)
#pragma no_side_effect(acosh, asinh, atanh, cbrt)
#pragma no_side_effect(logb, nextafter, remainder)
#pragma no_side_effect(expm1, ilogb, log1p, rint)
#endif
/* END adopted by C99 */
#endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || ... */

#if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE)
/*
 * SVID
 */
extern int matherr(struct exception *);

/*
 * IEEE Test Vector
 */
extern double significand(double);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(significand)
#pragma does_not_write_global_data(significand)
#pragma no_side_effect(significand)
#endif

extern int signgamf;				/* deprecated; use signgam */
extern int signgaml;				/* deprecated; use signgam */

extern int isnanf(float);
extern int isnanl(long double);
extern float gammaf(float);		/* deprecated; use lgammaf */
extern float gammaf_r(float, int *);	/* deprecated; use lgammaf_r */
extern float j0f(float);
extern float j1f(float);
extern float jnf(int, float);
extern float lgammaf_r(float, int *);
extern float scalbf(float, float);
extern float significandf(float);
extern float y0f(float);
extern float y1f(float);
extern float ynf(int, float);
extern long double gammal(long double);	/* deprecated; use lgammal */
extern long double gammal_r(long double, int *);	/* deprecated */
extern long double j0l(long double);
extern long double j1l(long double);
extern long double jnl(int, long double);
extern long double lgammal_r(long double, int *);
extern long double scalbl(long double, long double);
extern long double significandl(long double);
extern long double y0l(long double);
extern long double y1l(long double);
extern long double ynl(int, long double);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(isnanf, isnanl)
#pragma does_not_write_global_data(isnanf, isnanl)
#pragma no_side_effect(isnanf, isnanl)
#pragma does_not_read_global_data(gammaf_r, j0f, j1f, jnf, lgammaf_r, scalbf)
#pragma does_not_read_global_data(significandf, y0f, y1f, ynf)
#pragma does_not_write_global_data(j0f, j1f, jnf, scalbf)
#pragma does_not_write_global_data(significandf, y0f, y1f, ynf)
#pragma no_side_effect(j0f, j1f, jnf, scalbf)
#pragma no_side_effect(significandf, y0f, y1f, ynf)
#pragma does_not_read_global_data(gammal_r, j0l, j1l, jnl, lgammal_r, scalbl)
#pragma does_not_read_global_data(significandl, y0l, y1l, ynl)
#pragma does_not_write_global_data(j0l, j1l, jnl, scalbl)
#pragma does_not_write_global_data(significandl, y0l, y1l, ynl)
#pragma no_side_effect(j0l, j1l, jnl, scalbl)
#pragma no_side_effect(significandl, y0l, y1l, ynl)
#endif

/*
 * for sin+cos->sincos transformation
 */
extern void sincos(double, double *, double *);
extern void sincosf(float, float *, float *);
extern void sincosl(long double, long double *, long double *);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(sincos, sincosf, sincosl)
#endif

/* BEGIN adopted by C99 */
/*
 * Functions callable from C, intended to support IEEE arithmetic.
 */
extern double copysign(double, double);
extern double scalbn(double, int);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(copysign, scalbn)
#pragma does_not_write_global_data(copysign, scalbn)
#pragma no_side_effect(copysign, scalbn)
#endif
/* END adopted by C99 */

/*
 * Reentrant version of gamma & lgamma; passes signgam back by reference
 * as the second argument; user must allocate space for signgam.
 */
extern double gamma_r(double, int *);	/* deprecated; use lgamma_r */
extern double lgamma_r(double, int *);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(gamma_r, lgamma_r)
#endif

/* BEGIN adopted by C99 */
extern float modff(float, float *);

#if defined(__MATHERR_ERRNO_DONTCARE)
#pragma does_not_read_global_data(modff)
#endif
/* END adopted by C99 */

#if defined(__EXTENSIONS__) || !defined(__cplusplus)
#include <floatingpoint.h>
#endif
#endif	/* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) */
#endif	/* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) || ... */

#if defined(__cplusplus) && defined(__GNUC__)
#undef	exception
#endif

#ifdef __cplusplus
}
#endif

#endif	/* _MATH_H */