]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/math.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / math.h
1 /* $NetBSD: math.h,v 1.44 2006/03/25 16:41:11 xtraeme Exp $ */
2
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14 /*
15 * @(#)fdlibm.h 5.1 93/09/24
16 */
17
18 #ifndef _MATH_H_
19 #define _MATH_H_
20
21 #include <sys/EfiCdefs.h>
22 #include <sys/featuretest.h>
23
24 union __float_u {
25 unsigned char __dummy[sizeof(float)];
26 float __val;
27 };
28
29 union __double_u {
30 unsigned char __dummy[sizeof(double)];
31 double __val;
32 };
33
34 union __long_double_u {
35 unsigned char __dummy[sizeof(long double)];
36 long double __val;
37 };
38
39 #include <machine/math.h> /* may use __float_u, __double_u,
40 or __long_double_u */
41
42 #ifdef __HAVE_LONG_DOUBLE
43 #define __fpmacro_unary_floating(__name, __arg0) \
44 /* LINTED */ \
45 ((sizeof (__arg0) == sizeof (float)) \
46 ? __ ## __name ## f (__arg0) \
47 : (sizeof (__arg0) == sizeof (double)) \
48 ? __ ## __name ## d (__arg0) \
49 : __ ## __name ## l (__arg0))
50 #else
51 #define __fpmacro_unary_floating(__name, __arg0) \
52 /* LINTED */ \
53 ((sizeof (__arg0) == sizeof (float)) \
54 ? __ ## __name ## f (__arg0) \
55 : __ ## __name ## d (__arg0))
56 #endif /* __HAVE_LONG_DOUBLE */
57
58 /*
59 * ANSI/POSIX
60 */
61 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
62 extern const union __double_u __infinity;
63 #define HUGE_VAL __infinity.__val
64
65 /*
66 * ISO C99
67 */
68 /* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */
69 extern const union __float_u __infinityf;
70 #define HUGE_VALF __infinityf.__val
71
72 extern const union __long_double_u __infinityl;
73 #define HUGE_VALL __infinityl.__val
74
75 /* 7.12#4 INFINITY */
76 #ifdef __INFINITY
77 #define INFINITY __INFINITY /* float constant which overflows */
78 #else
79 #define INFINITY HUGE_VALF /* positive infinity */
80 #endif /* __INFINITY */
81
82 /* 7.12#5 NAN: a quiet NaN, if supported */
83 #ifdef __HAVE_NANF
84 extern const union __float_u __nanf;
85 #define NAN __nanf.__val
86 #endif /* __HAVE_NANF */
87
88 /* 7.12#6 number classification macros */
89 #define FP_INFINITE 0x00
90 #define FP_NAN 0x01
91 #define FP_NORMAL 0x02
92 #define FP_SUBNORMAL 0x03
93 #define FP_ZERO 0x04
94 /* NetBSD extensions */
95 #define _FP_LOMD 0x80 /* range for machine-specific classes */
96 #define _FP_HIMD 0xff
97
98 /*
99 * XOPEN/SVID
100 */
101 #define M_E 2.7182818284590452354 /* e */
102 #define M_LOG2E 1.4426950408889634074 /* log 2e */
103 #define M_LOG10E 0.43429448190325182765 /* log 10e */
104 #define M_LN2 0.69314718055994530942 /* log e2 */
105 #define M_LN10 2.30258509299404568402 /* log e10 */
106 #define M_PI 3.14159265358979323846 /* pi */
107 #define M_PI_2 1.57079632679489661923 /* pi/2 */
108 #define M_PI_4 0.78539816339744830962 /* pi/4 */
109 #define M_1_PI 0.31830988618379067154 /* 1/pi */
110 #define M_2_PI 0.63661977236758134308 /* 2/pi */
111 #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
112 #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
113 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
114
115 #define MAXFLOAT ((float)3.40282346638528860e+38)
116 extern int signgam;
117
118 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
119
120 #define _LIB_VERSION_TYPE enum fdversion
121 #define _LIB_VERSION _fdlib_version
122
123 /* if global variable _LIB_VERSION is not desirable, one may
124 * change the following to be a constant by:
125 * #define _LIB_VERSION_TYPE const enum version
126 * In that case, after one initializes the value _LIB_VERSION (see
127 * s_lib_version.c) during compile time, it cannot be modified
128 * in the middle of a program
129 */
130 extern _LIB_VERSION_TYPE _LIB_VERSION;
131
132 #define _IEEE_ fdlibm_ieee
133 #define _SVID_ fdlibm_svid
134 #define _XOPEN_ fdlibm_xopen
135 #define _POSIX_ fdlibm_posix
136
137 #ifndef __cplusplus
138 struct exception {
139 int type;
140 char *name;
141 double arg1;
142 double arg2;
143 double retval;
144 };
145 #endif
146
147 #define HUGE MAXFLOAT
148
149 /*
150 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
151 * (one may replace the following line by "#include <values.h>")
152 */
153
154 #define X_TLOSS 1.41484755040568800000e+16
155
156 #define DOMAIN 1
157 #define SING 2
158 #define OVERFLOW 3
159 #define UNDERFLOW 4
160 #define TLOSS 5
161 #define PLOSS 6
162
163
164 __BEGIN_DECLS
165 /*
166 * ANSI/POSIX
167 */
168 double acos(double);
169 double asin(double);
170 double atan(double);
171 double atan2(double, double);
172 double cos(double);
173 double sin(double);
174 double tan(double);
175
176 double cosh(double);
177 double sinh(double);
178 double tanh(double);
179
180 double exp(double);
181 double frexp(double, int *);
182 double ldexp(double, int);
183 double log(double);
184 double log2(double);
185 double log10(double);
186 double modf(double, double *);
187
188 double pow(double, double);
189 double sqrt(double);
190
191 double ceil(double);
192 double fabs(double);
193 double floor(double);
194 double fmod(double, double);
195
196 //#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
197 //double erf(double);
198 //double erfc(double);
199 //double gamma(double);
200 //double hypot(double, double);
201 int finite(double);
202 //double j0(double);
203 //double j1(double);
204 //double jn(int, double);
205 //double lgamma(double);
206 //double y0(double);
207 //double y1(double);
208 //double yn(int, double);
209
210 //#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
211 //double acosh(double);
212 //double asinh(double);
213 //double atanh(double);
214 //double cbrt(double);
215 double expm1(double);
216 //int ilogb(double);
217 //double log1p(double);
218 //double logb(double);
219 //double nextafter(double, double);
220 //double remainder(double, double);
221 //double rint(double);
222 //double scalb(double, double);
223 //#endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/
224 //#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
225
226 /* 7.12.3.1 int fpclassify(real-floating x) */
227 #define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)
228
229 #if 0
230 /*
231 * ISO C99
232 */
233 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
234 !defined(_XOPEN_SOURCE) || \
235 ((__STDC_VERSION__ - 0) >= 199901L) || \
236 ((_POSIX_C_SOURCE - 0) >= 200112L) || \
237 ((_XOPEN_SOURCE - 0) >= 600) || \
238 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
239
240 /* 7.12.3.2 int isfinite(real-floating x) */
241 #define isfinite(__x) __fpmacro_unary_floating(isfinite, __x)
242
243 /* 7.12.3.5 int isnormal(real-floating x) */
244 #define isnormal(__x) (fpclassify(__x) == FP_NORMAL)
245
246 /* 7.12.3.6 int signbit(real-floating x) */
247 #define signbit(__x) __fpmacro_unary_floating(signbit, __x)
248
249 /* 7.12.4 trigonometric */
250
251 float acosf(float);
252 float asinf(float);
253 float atanf(float);
254 float atan2f(float, float);
255 float cosf(float);
256 float sinf(float);
257 float tanf(float);
258
259 /* 7.12.5 hyperbolic */
260
261 float acoshf(float);
262 float asinhf(float);
263 float atanhf(float);
264 float coshf(float);
265 float sinhf(float);
266 float tanhf(float);
267
268 /* 7.12.6 exp / log */
269
270 float expf(float);
271 float expm1f(float);
272 float frexpf(float, int *);
273 int ilogbf(float);
274 float ldexpf(float, int);
275 float logf(float);
276 float log2f(float);
277 float log10f(float);
278 float log1pf(float);
279 float logbf(float);
280 float modff(float, float *);
281 float scalbnf(float, int);
282
283 /* 7.12.7 power / absolute */
284
285 float cbrtf(float);
286 float fabsf(float);
287 float hypotf(float, float);
288 float powf(float, float);
289 float sqrtf(float);
290
291 /* 7.12.8 error / gamma */
292
293 float erff(float);
294 float erfcf(float);
295 float lgammaf(float);
296
297 /* 7.12.9 nearest integer */
298
299 float ceilf(float);
300 float floorf(float);
301 float rintf(float);
302 double round(double);
303 float roundf(float);
304 double trunc(double);
305 float truncf(float);
306 long int lrint(double);
307 long int lrintf(float);
308 /* LONGLONG */
309 long long int llrint(double);
310 /* LONGLONG */
311 long long int llrintf(float);
312 long int lround(double);
313 long int lroundf(float);
314 /* LONGLONG */
315 long long int llround(double);
316 /* LONGLONG */
317 long long int llroundf(float);
318
319 /* 7.12.10 remainder */
320
321 float fmodf(float, float);
322 float remainderf(float, float);
323
324 /* 7.2.11 manipulation */
325
326 float copysignf(float, float);
327 double nan(const char *);
328 float nanf(const char *);
329 long double nanl(const char *);
330 float nextafterf(float, float);
331
332
333 #endif /* !_ANSI_SOURCE && ... */
334
335 #if defined(_NETBSD_SOURCE)
336 #ifndef __cplusplus
337 int matherr(struct exception *);
338 #endif
339 #endif /* _NETBSD_SOURCE */
340
341 /*
342 * IEEE Test Vector
343 */
344 double significand(double);
345 #endif /* if 0 */
346
347 /* 7.12.3.3 int isinf(real-floating x) */
348 #ifdef __isinf
349 #define isinf(__x) __isinf(__x)
350 #else
351 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)
352 #endif
353
354 /* 7.12.3.4 int isnan(real-floating x) */
355 #ifdef __isnan
356 #define isnan(__x) __isnan(__x)
357 #else
358 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)
359 #endif
360
361 /*
362 * Functions callable from C, intended to support IEEE arithmetic.
363 */
364 double copysign(double, double);
365 double scalbn(double, int);
366
367 #if 0
368 /*
369 * BSD math library entry points
370 */
371 #ifndef __MATH_PRIVATE__
372 double cabs(/* struct complex { double r; double i; } */);
373 #endif
374 double drem(double, double);
375
376
377 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
378 /*
379 * Reentrant version of gamma & lgamma; passes signgam back by reference
380 * as the second argument; user must allocate space for signgam.
381 */
382 double gamma_r(double, int *);
383 double lgamma_r(double, int *);
384 #endif /* _NETBSD_SOURCE || _REENTRANT */
385
386
387 #if defined(_NETBSD_SOURCE)
388
389 /* float versions of ANSI/POSIX functions */
390
391 float gammaf(float);
392 int isinff(float);
393 int isnanf(float);
394 int finitef(float);
395 float j0f(float);
396 float j1f(float);
397 float jnf(int, float);
398 float y0f(float);
399 float y1f(float);
400 float ynf(int, float);
401
402 float scalbf(float, float);
403
404 /*
405 * float version of IEEE Test Vector
406 */
407 float significandf(float);
408
409 /*
410 * float versions of BSD math library entry points
411 */
412 #ifndef __MATH_PRIVATE__
413 float cabsf(/* struct complex { float r; float i; } */);
414 #endif
415 float dremf(float, float);
416 #endif /* _NETBSD_SOURCE */
417
418 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
419 /*
420 * Float versions of reentrant version of gamma & lgamma; passes
421 * signgam back by reference as the second argument; user must
422 * allocate space for signgam.
423 */
424 float gammaf_r(float, int *);
425 float lgammaf_r(float, int *);
426 #endif /* !... || _REENTRANT */
427
428 #endif /* if 0 */
429
430 ///*
431 // * Library implementation
432 // */
433 int __fpclassifyf(float);
434 int __fpclassifyd(double);
435 //int __isfinitef(float);
436 //int __isfinited(double);
437 int __isinff(float);
438 int __isinfd(double);
439 int __isnanf(float);
440 int __isnand(double);
441 //int __signbitf(float);
442 //int __signbitd(double);
443
444 //#ifdef __HAVE_LONG_DOUBLE
445 int __fpclassifyl(long double);
446 //int __isfinitel(long double);
447 int __isinfl(long double);
448 int __isnanl(long double);
449 //int __signbitl(long double);
450 //#endif
451 __END_DECLS
452
453 #endif /* _MATH_H_ */