xref: /relibc/openlibm/include/openlibm_math.h (revision c08bd962f2f00e09e46989c18fcdd8cbbc2caf6d)
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
5  * Developed at SunPro, a Sun Microsystems, Inc. business.
6  * Permission to use, copy, modify, and distribute this
7  * software is freely granted, provided that this notice
8  * is preserved.
9  * ====================================================
10  */
11 
12 /*
13  * from: @(#)fdlibm.h 5.1 93/09/24
14  * $FreeBSD: src/lib/msun/src/openlibm.h,v 1.82 2011/11/12 19:55:48 theraven Exp $
15  */
16 
17 #ifdef OPENLIBM_USE_HOST_MATH_H
18 #include <math.h>
19 #else /* !OPENLIBM_USE_HOST_MATH_H */
20 
21 #ifndef OPENLIBM_MATH_H
22 #define	OPENLIBM_MATH_H
23 
24 #if (defined(_WIN32) || defined (_MSC_VER)) && !defined(__WIN32__)
25     #define __WIN32__
26 #endif
27 
28 #ifndef __arm__
29 #define LONG_DOUBLE
30 #endif
31 
32 #ifndef __pure2
33 #define __pure2
34 #endif
35 
36 /*
37  * ANSI/POSIX
38  */
39 extern const union __infinity_un {
40 	unsigned char	__uc[8];
41 	double		__ud;
42 } __infinity;
43 
44 extern const union __nan_un {
45 	unsigned char	__uc[sizeof(float)];
46 	float		__uf;
47 } __nan;
48 
49 /* VBS
50 #if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
51 #define	__MATH_BUILTIN_CONSTANTS
52 #endif
53 
54 #if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
55 #define	__MATH_BUILTIN_RELOPS
56 #endif
57 */
58 
59 //VBS begin
60 #define __MATH_BUILTIN_CONSTANTS
61 #define	__MATH_BUILTIN_RELOPS
62 #ifndef __ISO_C_VISIBLE
63 #define __ISO_C_VISIBLE 1999
64 #endif
65 //VBS end
66 
67 #ifdef __MATH_BUILTIN_CONSTANTS
68 #define	HUGE_VAL	__builtin_huge_val()
69 #else
70 #define	HUGE_VAL	(__infinity.__ud)
71 #endif
72 
73 #if __ISO_C_VISIBLE >= 1999
74 #define	FP_ILOGB0	(-INT_MAX)
75 #define	FP_ILOGBNAN	INT_MAX
76 
77 #ifdef __MATH_BUILTIN_CONSTANTS
78 #define	HUGE_VALF	__builtin_huge_valf()
79 #define	HUGE_VALL	__builtin_huge_vall()
80 #define	INFINITY	__builtin_inff()
81 #define	NAN		__builtin_nanf("")
82 #else
83 #define	HUGE_VALF	(float)HUGE_VAL
84 #define	HUGE_VALL	(long double)HUGE_VAL
85 #define	INFINITY	HUGE_VALF
86 #define	NAN		(__nan.__uf)
87 #endif /* __MATH_BUILTIN_CONSTANTS */
88 
89 #define	MATH_ERRNO	1
90 #define	MATH_ERREXCEPT	2
91 #define	math_errhandling	MATH_ERREXCEPT
92 
93 #define	FP_FAST_FMAF	1
94 #ifdef __ia64__
95 #define	FP_FAST_FMA	1
96 #define	FP_FAST_FMAL	1
97 #endif
98 
99 /* Symbolic constants to classify floating point numbers. */
100 #define	FP_INFINITE	0x01
101 #define	FP_NAN		0x02
102 #define	FP_NORMAL	0x04
103 #define	FP_SUBNORMAL	0x08
104 #define	FP_ZERO		0x10
105 #define	fpclassify(x) \
106     ((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
107     : (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
108     : __fpclassifyl(x))
109 
110 #define	isfinite(x)					\
111     ((sizeof (x) == sizeof (float)) ? __isfinitef(x)	\
112     : (sizeof (x) == sizeof (double)) ? __isfinite(x)	\
113     : __isfinitel(x))
114 #define	isinf(x)					\
115     ((sizeof (x) == sizeof (float)) ? __isinff(x)	\
116     : (sizeof (x) == sizeof (double)) ? isinf(x)	\
117     : __isinfl(x))
118 #define	isnan(x)					\
119     ((sizeof (x) == sizeof (float)) ? __isnanf(x)	\
120     : (sizeof (x) == sizeof (double)) ? isnan(x)	\
121     : __isnanl(x))
122 #define	isnormal(x)					\
123     ((sizeof (x) == sizeof (float)) ? __isnormalf(x)	\
124     : (sizeof (x) == sizeof (double)) ? __isnormal(x)	\
125     : __isnormall(x))
126 
127 #ifdef __MATH_BUILTIN_RELOPS
128 #define	isgreater(x, y)		__builtin_isgreater((x), (y))
129 #define	isgreaterequal(x, y)	__builtin_isgreaterequal((x), (y))
130 #define	isless(x, y)		__builtin_isless((x), (y))
131 #define	islessequal(x, y)	__builtin_islessequal((x), (y))
132 #define	islessgreater(x, y)	__builtin_islessgreater((x), (y))
133 #define	isunordered(x, y)	__builtin_isunordered((x), (y))
134 #else
135 #define	isgreater(x, y)		(!isunordered((x), (y)) && (x) > (y))
136 #define	isgreaterequal(x, y)	(!isunordered((x), (y)) && (x) >= (y))
137 #define	isless(x, y)		(!isunordered((x), (y)) && (x) < (y))
138 #define	islessequal(x, y)	(!isunordered((x), (y)) && (x) <= (y))
139 #define	islessgreater(x, y)	(!isunordered((x), (y)) && \
140 					((x) > (y) || (y) > (x)))
141 #define	isunordered(x, y)	(isnan(x) || isnan(y))
142 #endif /* __MATH_BUILTIN_RELOPS */
143 
144 #define	signbit(x)					\
145     ((sizeof (x) == sizeof (float)) ? __signbitf(x)	\
146     : (sizeof (x) == sizeof (double)) ? __signbit(x)	\
147     : __signbitl(x))
148 
149 //VBS
150 //typedef	__double_t	double_t;
151 //typedef	__float_t	float_t;
152 #endif /* __ISO_C_VISIBLE >= 1999 */
153 
154 /*
155  * XOPEN/SVID
156  */
157 #if __BSD_VISIBLE || __XSI_VISIBLE
158 #define	M_E		2.7182818284590452354	/* e */
159 #define	M_LOG2E		1.4426950408889634074	/* log 2e */
160 #define	M_LOG10E	0.43429448190325182765	/* log 10e */
161 #define	M_LN2		0.69314718055994530942	/* log e2 */
162 #define	M_LN10		2.30258509299404568402	/* log e10 */
163 #define	M_PI		3.14159265358979323846	/* pi */
164 #define	M_PI_2		1.57079632679489661923	/* pi/2 */
165 #define	M_PI_4		0.78539816339744830962	/* pi/4 */
166 #define	M_1_PI		0.31830988618379067154	/* 1/pi */
167 #define	M_2_PI		0.63661977236758134308	/* 2/pi */
168 #define	M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
169 #define	M_SQRT2		1.41421356237309504880	/* sqrt(2) */
170 #define	M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
171 
172 #define	MAXFLOAT	((float)3.40282346638528860e+38)
173 
174 #ifndef OPENLIBM_ONLY_THREAD_SAFE
175 extern int signgam;
176 #endif
177 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
178 
179 #if __BSD_VISIBLE
180 #if 0
181 /* Old value from 4.4BSD-Lite openlibm.h; this is probably better. */
182 #define	HUGE		HUGE_VAL
183 #else
184 #define	HUGE		MAXFLOAT
185 #endif
186 #endif /* __BSD_VISIBLE */
187 
188 /*
189  * Most of these functions depend on the rounding mode and have the side
190  * effect of raising floating-point exceptions, so they are not declared
191  * as __pure2.  In C99, FENV_ACCESS affects the purity of these functions.
192  */
193 
194 #if defined(__cplusplus)
195 extern "C" {
196 #endif
197 /*
198  * ANSI/POSIX
199  */
200 int	__fpclassifyd(double) __pure2;
201 int	__fpclassifyf(float) __pure2;
202 int	__fpclassifyl(long double) __pure2;
203 int	__isfinitef(float) __pure2;
204 int	__isfinite(double) __pure2;
205 int	__isfinitel(long double) __pure2;
206 int	__isinff(float) __pure2;
207 int	__isinfl(long double) __pure2;
208 int	__isnanf(float) __pure2;
209 int	__isnanl(long double) __pure2;
210 int	__isnormalf(float) __pure2;
211 int	__isnormal(double) __pure2;
212 int	__isnormall(long double) __pure2;
213 int	__signbit(double) __pure2;
214 int	__signbitf(float) __pure2;
215 int	__signbitl(long double) __pure2;
216 
217 double	acos(double);
218 double	asin(double);
219 double	atan(double);
220 double	atan2(double, double);
221 double	cos(double);
222 double	sin(double);
223 double	tan(double);
224 
225 double	cosh(double);
226 double	sinh(double);
227 double	tanh(double);
228 
229 double	exp(double);
230 double	frexp(double, int *);	/* fundamentally !__pure2 */
231 double	ldexp(double, int);
232 double	log(double);
233 double	log10(double);
234 double	modf(double, double *);	/* fundamentally !__pure2 */
235 
236 double	pow(double, double);
237 double	sqrt(double);
238 
239 double	ceil(double);
240 double	fabs(double) __pure2;
241 double	floor(double);
242 double	fmod(double, double);
243 
244 /*
245  * These functions are not in C90.
246  */
247 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
248 double	acosh(double);
249 double	asinh(double);
250 double	atanh(double);
251 double	cbrt(double);
252 double	erf(double);
253 double	erfc(double);
254 double	exp2(double);
255 double	expm1(double);
256 double	fma(double, double, double);
257 double	hypot(double, double);
258 int	ilogb(double) __pure2;
259 int	(isinf)(double) __pure2;
260 int	(isnan)(double) __pure2;
261 double	lgamma(double);
262 long long llrint(double);
263 long long llround(double);
264 double	log1p(double);
265 double	log2(double);
266 double	logb(double);
267 long	lrint(double);
268 long	lround(double);
269 double	nan(const char *) __pure2;
270 double	nextafter(double, double);
271 double	remainder(double, double);
272 double	remquo(double, double, int *);
273 double	rint(double);
274 #endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
275 
276 #if __BSD_VISIBLE || __XSI_VISIBLE
277 double	j0(double);
278 double	j1(double);
279 double	jn(int, double);
280 double	y0(double);
281 double	y1(double);
282 double	yn(int, double);
283 
284 #if __XSI_VISIBLE <= 600 || __BSD_VISIBLE
285 double	scalb(double, double);
286 #endif
287 #endif /* __BSD_VISIBLE || __XSI_VISIBLE */
288 
289 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
290 double	copysign(double, double) __pure2;
291 double	fdim(double, double);
292 double	fmax(double, double) __pure2;
293 double	fmin(double, double) __pure2;
294 double	nearbyint(double);
295 double	round(double);
296 double	scalbln(double, long);
297 double	scalbn(double, int);
298 double	tgamma(double);
299 double	trunc(double);
300 #endif
301 
302 /*
303  * BSD math library entry points
304  */
305 #if __BSD_VISIBLE
306 int	isnanf(float) __pure2;
307 
308 /*
309  * Reentrant version of lgamma; passes signgam back by reference as the
310  * second argument; user must allocate space for signgam.
311  */
312 double	lgamma_r(double, int *);
313 
314 /*
315  * Single sine/cosine function.
316  */
317 void	sincos(double, double *, double *);
318 #endif /* __BSD_VISIBLE */
319 
320 /* float versions of ANSI/POSIX functions */
321 #if __ISO_C_VISIBLE >= 1999
322 float	acosf(float);
323 float	asinf(float);
324 float	atanf(float);
325 float	atan2f(float, float);
326 float	cosf(float);
327 float	sinf(float);
328 float	tanf(float);
329 
330 float	coshf(float);
331 float	sinhf(float);
332 float	tanhf(float);
333 
334 float	exp2f(float);
335 float	expf(float);
336 float	expm1f(float);
337 float	frexpf(float, int *);	/* fundamentally !__pure2 */
338 int	ilogbf(float) __pure2;
339 float	ldexpf(float, int);
340 float	log10f(float);
341 float	log1pf(float);
342 float	log2f(float);
343 float	logf(float);
344 float	modff(float, float *);	/* fundamentally !__pure2 */
345 
346 float	powf(float, float);
347 float	sqrtf(float);
348 
349 float	ceilf(float);
350 float	fabsf(float) __pure2;
351 float	floorf(float);
352 float	fmodf(float, float);
353 float	roundf(float);
354 
355 float	erff(float);
356 float	erfcf(float);
357 float	hypotf(float, float);
358 float	lgammaf(float);
359 float	tgammaf(float);
360 
361 float	acoshf(float);
362 float	asinhf(float);
363 float	atanhf(float);
364 float	cbrtf(float);
365 float	logbf(float);
366 float	copysignf(float, float) __pure2;
367 long long llrintf(float);
368 long long llroundf(float);
369 long	lrintf(float);
370 long	lroundf(float);
371 float	nanf(const char *) __pure2;
372 float	nearbyintf(float);
373 float	nextafterf(float, float);
374 float	remainderf(float, float);
375 float	remquof(float, float, int *);
376 float	rintf(float);
377 float	scalblnf(float, long);
378 float	scalbnf(float, int);
379 float	truncf(float);
380 
381 float	fdimf(float, float);
382 float	fmaf(float, float, float);
383 float	fmaxf(float, float) __pure2;
384 float	fminf(float, float) __pure2;
385 #endif
386 
387 /*
388  * float versions of BSD math library entry points
389  */
390 #if __BSD_VISIBLE
391 float	dremf(float, float);
392 float	j0f(float);
393 float	j1f(float);
394 float	jnf(int, float);
395 float	scalbf(float, float);
396 float	y0f(float);
397 float	y1f(float);
398 float	ynf(int, float);
399 
400 /*
401  * Float versions of reentrant version of lgamma; passes signgam back by
402  * reference as the second argument; user must allocate space for signgam.
403  */
404 float	lgammaf_r(float, int *);
405 
406 /*
407  * Single sine/cosine function.
408  */
409 void	sincosf(float, float *, float *);
410 #endif	/* __BSD_VISIBLE */
411 
412 /*
413  * long double versions of ISO/POSIX math functions
414  */
415 #if __ISO_C_VISIBLE >= 1999
416 long double	acoshl(long double);
417 long double	acosl(long double);
418 long double	asinhl(long double);
419 long double	asinl(long double);
420 long double	atan2l(long double, long double);
421 long double	atanhl(long double);
422 long double	atanl(long double);
423 long double	cbrtl(long double);
424 long double	ceill(long double);
425 long double	copysignl(long double, long double) __pure2;
426 long double	coshl(long double);
427 long double	cosl(long double);
428 long double	erfcl(long double);
429 long double	erfl(long double);
430 long double	exp2l(long double);
431 long double	expl(long double);
432 long double	expm1l(long double);
433 long double	fabsl(long double) __pure2;
434 long double	fdiml(long double, long double);
435 long double	floorl(long double);
436 long double	fmal(long double, long double, long double);
437 long double	fmaxl(long double, long double) __pure2;
438 long double	fminl(long double, long double) __pure2;
439 long double	fmodl(long double, long double);
440 long double	frexpl(long double value, int *); /* fundamentally !__pure2 */
441 long double	hypotl(long double, long double);
442 int		ilogbl(long double) __pure2;
443 long double	ldexpl(long double, int);
444 long double	lgammal(long double);
445 long long	llrintl(long double);
446 long long	llroundl(long double);
447 long double	log10l(long double);
448 long double	log1pl(long double);
449 long double	log2l(long double);
450 long double	logbl(long double);
451 long double	logl(long double);
452 long		lrintl(long double);
453 long		lroundl(long double);
454 long double	modfl(long double, long double *); /* fundamentally !__pure2 */
455 long double	nanl(const char *) __pure2;
456 long double	nearbyintl(long double);
457 long double	nextafterl(long double, long double);
458 double		nexttoward(double, long double);
459 float		nexttowardf(float, long double);
460 long double	nexttowardl(long double, long double);
461 long double	powl(long double, long double);
462 long double	remainderl(long double, long double);
463 long double	remquol(long double, long double, int *);
464 long double	rintl(long double);
465 long double	roundl(long double);
466 long double	scalblnl(long double, long);
467 long double	scalbnl(long double, int);
468 long double	sinhl(long double);
469 long double	sinl(long double);
470 long double	sqrtl(long double);
471 long double	tanhl(long double);
472 long double	tanl(long double);
473 long double	tgammal(long double);
474 long double	truncl(long double);
475 #endif /* __ISO_C_VISIBLE >= 1999 */
476 
477 /* Reentrant version of lgammal. */
478 #if __BSD_VISIBLE
479 long double	lgammal_r(long double, int *);
480 
481 /*
482  * Single sine/cosine function.
483  */
484 void	sincosl(long double, long double *, long double *);
485 #endif	/* __BSD_VISIBLE */
486 
487 #if defined(__cplusplus)
488 }
489 #endif
490 #endif /* !OPENLIBM_MATH_H */
491 
492 #endif /* OPENLIBM_USE_HOST_MATH_H */
493