]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/math.h
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / Include / math.h
CommitLineData
a430bdb1 1/** @file\r
2 Floating-point Math functions and macros.\r
3\r
4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials are licensed and made available under\r
6 the terms and conditions of the BSD License that accompanies this distribution.\r
7 The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
2aa62f2b 12\r
2aa62f2b 13 * ====================================================\r
14 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
15 *\r
16 * Developed at SunPro, a Sun Microsystems, Inc. business.\r
17 * Permission to use, copy, modify, and distribute this\r
18 * software is freely granted, provided that this notice\r
19 * is preserved.\r
20 * ====================================================\r
2aa62f2b 21\r
a430bdb1 22 NetBSD: math.h,v 1.44 2006/03/25 16:41:11 xtraeme Exp\r
23 dlibm.h 5.1 93/09/24\r
24**/\r
2aa62f2b 25#ifndef _MATH_H_\r
26#define _MATH_H_\r
27\r
28#include <sys/EfiCdefs.h>\r
a430bdb1 29#include <sys/featuretest.h>\r
2aa62f2b 30\r
a430bdb1 31/** @{\r
32 @brief These are forward references to unions and macros used internaly\r
33 by the implementation of the math functions and macros.\r
34**/\r
2aa62f2b 35union __float_u {\r
36 unsigned char __dummy[sizeof(float)];\r
37 float __val;\r
38};\r
39\r
40union __double_u {\r
41 unsigned char __dummy[sizeof(double)];\r
42 double __val;\r
43};\r
44\r
45union __long_double_u {\r
46 unsigned char __dummy[sizeof(long double)];\r
47 long double __val;\r
48};\r
49\r
a430bdb1 50#include <machine/math.h> /* may use __float_u, __double_u, or __long_double_u */\r
2aa62f2b 51\r
52#ifdef __HAVE_LONG_DOUBLE\r
53#define __fpmacro_unary_floating(__name, __arg0) \\r
54 /* LINTED */ \\r
55 ((sizeof (__arg0) == sizeof (float)) \\r
56 ? __ ## __name ## f (__arg0) \\r
57 : (sizeof (__arg0) == sizeof (double)) \\r
58 ? __ ## __name ## d (__arg0) \\r
59 : __ ## __name ## l (__arg0))\r
60#else\r
61#define __fpmacro_unary_floating(__name, __arg0) \\r
62 /* LINTED */ \\r
63 ((sizeof (__arg0) == sizeof (float)) \\r
64 ? __ ## __name ## f (__arg0) \\r
65 : __ ## __name ## d (__arg0))\r
66#endif /* __HAVE_LONG_DOUBLE */\r
67\r
a430bdb1 68extern const union __double_u __infinity;\r
69extern const union __float_u __infinityf;\r
70extern const union __long_double_u __infinityl;\r
71\r
72/* C99 7.12.3.1 int fpclassify(real-floating x) */\r
73#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x)\r
74\r
75/* C99 7.12.3.3 int isinf(real-floating x) */\r
76#ifdef __isinf\r
77 #define isinf(__x) __isinf(__x)\r
78#else\r
79 #define isinf(__x) __fpmacro_unary_floating(isinf, __x)\r
80#endif\r
81\r
82/* C99 7.12.3.4 int isnan(real-floating x) */\r
83#ifdef __isnan\r
84 #define isnan(__x) __isnan(__x)\r
85#else\r
86 #define isnan(__x) __fpmacro_unary_floating(isnan, __x)\r
87#endif\r
88/*@)*/\r
89\r
90/*#############################################################\r
91 * ISO C95\r
2aa62f2b 92 */\r
a430bdb1 93\r
94/**@{\r
95 Double, float, and long double versions, respectively, of HUGE_VAL.\r
96*/\r
2aa62f2b 97#define HUGE_VAL __infinity.__val\r
a430bdb1 98#define HUGE_VALF __infinityf.__val\r
99#define HUGE_VALL __infinityl.__val\r
100/*@)*/\r
2aa62f2b 101\r
a430bdb1 102__BEGIN_DECLS\r
2aa62f2b 103/*\r
a430bdb1 104 * ANSI/POSIX\r
2aa62f2b 105 */\r
a430bdb1 106/** Compute the principal value of the arc cosine of Arg.\r
2aa62f2b 107\r
a430bdb1 108 @param[in] Arg The value to compute the arc cosine of.\r
2aa62f2b 109\r
a430bdb1 110 @return The computed value of the arc cosine of Arg in the interval [0,pi] radians.\r
111 If Arg is not in the interval [-1,+1], errno is set to EDOM.\r
112**/\r
113double acos(double Arg);\r
2aa62f2b 114\r
a430bdb1 115/** Compute the principal value of the arc sine of Arg.\r
2aa62f2b 116\r
a430bdb1 117 @param[in] Arg The value to compute the arc sine of.\r
118\r
119 @return The computed value of the arc sine of Arg in the interval [-pi/2,+pi/2] radians.\r
120 If Arg is not in the interval [-1,+1], errno is set to EDOM.\r
121**/\r
122double asin(double Arg);\r
123\r
124/** Compute the principal value of the arc tangent of Arg.\r
125\r
126 @param[in] Arg The value to compute the arc tangent of.\r
127\r
128 @return The computed value of the arc tangent of Arg in the interval [-pi/2,+pi/2] radians.\r
129**/\r
130double atan(double Arg);\r
131\r
132/** Compute the value of the arc tangent of (Num / Denom).\r
133 The sign of both arguments is used to determine the quadrant of the return value.\r
134\r
135 @param[in] Num The numerator of the value to compute the arc tangent of.\r
136 @param[in] Denom The denominator of the value to compute the arc tangent of.\r
137\r
138 @return The computed value of the arc tangent of (Num / Denom) in the interval [-pi,+pi] radians.\r
139**/\r
140double atan2(double Num, double Denom);\r
141\r
142/** Compute the value of the cosine of Arg, measured in radians.\r
143\r
144 @param[in] Arg The value to compute the cosine of.\r
145\r
146 @return The computed value of the cosine of Arg.\r
147**/\r
148double cos(double Arg);\r
149\r
150/** Compute the value of the sine of Arg.\r
151\r
152 @param[in] Arg The value to compute the sine of.\r
153\r
154 @return The computed value of the sine of Arg.\r
155**/\r
156double sin(double Arg);\r
157\r
158/** Compute the value of the tangent of Arg.\r
159\r
160 @param[in] Arg The value to compute the tangent of.\r
161\r
162 @return The computed value of the tangent of Arg.\r
163**/\r
164double tan(double Arg);\r
165\r
166\r
167/** Compute the value of the hyperbolic cosine of Arg.\r
168\r
169 @param[in] Arg The value to compute the hyperbolic cosine of.\r
170\r
171 @return The computed value of the hyperbolic cosine of Arg.\r
172 If the magnitude of Arg is too large, errno is set to ERANGE.\r
173**/\r
174double cosh(double Arg);\r
175\r
176/** Compute the value of the hyperbolic sine of Arg.\r
177\r
178 @param[in] Arg The value to compute the hyperbolic sine of.\r
179\r
180 @return The computed value of the hyperbolic sine of Arg.\r
181 If the magnitude of Arg is too large, errno is set to ERANGE.\r
182**/\r
183double sinh(double Arg);\r
184\r
185/** Compute the value of the hyperbolic tangent of Arg.\r
186\r
187 @param[in] Arg The value to compute the hyperbolic tangent of.\r
188\r
189 @return The computed value of the hyperbolic tangent of Arg.\r
190**/\r
191double tanh(double Arg);\r
192\r
193\r
194/** Compute the base-e exponential of Arg.\r
195\r
196 @param[in] Arg The value to compute the base-e exponential of.\r
197\r
198 @return The computed value of e**Arg.\r
199 If the magnitude of Arg is too large, errno is set to ERANGE.\r
200**/\r
201double exp(double Arg);\r
202\r
203/** Break a floating-point number into a normalized fraction and an integral power of 2.\r
204\r
205 @param[in] Value The floating-point value to be broken down.\r
206 @param[out] Exp A pointer to an integer object to receive the integral power of 2 exponent.\r
207\r
208 @return The frexp function returns a value R, such that Value == R**Exp.\r
209 If Value is zero, both parts of the result are zero.\r
210**/\r
211double frexp(double Value, int *Exp);\r
212\r
213/** Multiply a floating-point number, Value, by an integral power of 2, Exp.\r
214\r
215 @param[in] Value The floating-point value to be multiplied.\r
216 @param[out] Exp The integral power of 2 to multiply Value by.\r
217\r
218 @return The ldexp function returns a value R, such that R = Value x 2**Exp.\r
219 If a range error occurs, errno will be set to ERANGE.\r
220**/\r
221double ldexp(double Value, int Exp);\r
222\r
223/** Compute the natural logarithm of Arg.\r
224\r
225 @param[in] Arg The value to compute the natural logarithm of.\r
226\r
227 @return The log function returns log base-e of Arg. If Arg is negative, errno is set to EDOM.\r
228 Otherwise, errno will be set to ERANGE if a range error occurs.\r
229**/\r
230double log(double Arg);\r
231\r
232/** Compute the common (base-10) logarithm of Arg.\r
233\r
234 @param[in] Arg The value to compute the common logarithm of.\r
235\r
236 @return The log10 function returns log base-10 of Arg. If Arg is negative, errno is set to EDOM.\r
237 Otherwise, errno will be set to ERANGE if Arg is 0.\r
238**/\r
239double log10(double Arg);\r
240\r
241/** Compute the base-2 logarithm of Arg.\r
242\r
243 @param[in] Arg The value to compute the base-2 logarithm of.\r
244\r
245 @return The log function returns log base-2 of Arg. If Arg is negative, errno is set to EDOM.\r
246 Otherwise, errno will be set to ERANGE if Arg is 0.\r
247**/\r
248double log2(double Arg);\r
249\r
250/** Break Value into integral and fractional parts, each of which has the same type and sign\r
251 as Value. Store the integral part in the object pointed to by Integ and return the\r
252 fractional part.\r
253\r
254 @param[in] Value The value to compute the arc cosine of.\r
255 @param[out] Integ Pointer to where the integral component is to be stored.\r
256\r
257 @return The fractional part of Value is returned directly while the integral part is\r
258 returned in the location pointed to by Integ.\r
259**/\r
260double modf(double Value, double *Integ);\r
261\r
262/** Compute Value raised to the power Exp.\r
263\r
264 @param[in] Value The value to be raised.\r
265 @param[in] Exp The power Value is to be raised to.\r
266\r
267 @return The pow function returns Value**Exp. If an error occurs, errno will be set as follows:\r
268 - EDOM: Value is finite and negative and Exp is finite and not an integer.\r
269 - EDOM: Both Value and Exp are zero.\r
270 - EDOM: Value is zero and Exp is less than zero.\r
271**/\r
272double pow(double Value, double Exp);\r
273\r
274/** Compute the non-negative square root of Arg.\r
275\r
276 @param[in] Arg The value to compute the square root of.\r
277\r
278 @return The square root of Arg. If Arg is less than zero, errno is set to EDOM.\r
279**/\r
280double sqrt(double Arg);\r
281\r
282\r
283/** Compute the smallest integer value not less than Arg.\r
284\r
285 @param[in] Arg The value to compute the ceiling of.\r
286\r
287 @return The ceiling of Arg expressed as a floating-point number.\r
288**/\r
289double ceil(double Arg);\r
290\r
291/** Compute the absolute value of Arg.\r
292\r
293 @param[in] Arg The value to compute the absolute value of.\r
294\r
295 @return The absolute value of Arg.\r
296**/\r
297double fabs(double Arg);\r
298\r
299/** Compute the largest integer value not greater than Arg.\r
2aa62f2b 300\r
a430bdb1 301 @param[in] Arg The value to compute the floor of.\r
302\r
303 @return The largest integer value not greater than Arg, expressed as a floating-point number.\r
304**/\r
305double floor(double);\r
306\r
307/** Compute the floating-point remainder of A1 / A2.\r
308\r
309 @param[in] A1 The dividend.\r
310 @param[in] A2 The divisor.\r
311\r
312 @return The remainder of A1 / A2 with the same sign as A1. If A2 is zero, the fmod function\r
313 returns 0.\r
314**/\r
315double fmod(double A1, double A2);\r
316\r
317\r
318int finite(double);\r
319double expm1(double);\r
320\r
321/**@{\r
322 C99, Posix, or NetBSD functions that are not part of the C95 specification.\r
323**/\r
2aa62f2b 324/*\r
a430bdb1 325 * Functions callable from C, intended to support IEEE arithmetic.\r
2aa62f2b 326 */\r
a430bdb1 327double copysign(double, double);\r
328double scalbn(double, int);\r
2aa62f2b 329\r
a430bdb1 330/*\r
331 * Library implementation\r
332 */\r
333int __fpclassifyf(float);\r
334int __fpclassifyd(double);\r
335int __isinff(float);\r
336int __isinfd(double);\r
337int __isnanf(float);\r
338int __isnand(double);\r
339\r
340#ifdef __HAVE_LONG_DOUBLE\r
341 int __fpclassifyl(long double);\r
342 int __isinfl(long double);\r
343 int __isnanl(long double);\r
344#endif /* __HAVE_LONG_DOUBLE */\r
345/*@}*/\r
346\r
347__END_DECLS\r
348\r
349/**@{\r
350 Extensions provided by NetBSD but not required by the C95 standard.\r
351**/\r
2aa62f2b 352extern int signgam;\r
353\r
354enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};\r
355\r
356#define _LIB_VERSION_TYPE enum fdversion\r
357#define _LIB_VERSION _fdlib_version\r
358\r
a430bdb1 359/** If global variable _LIB_VERSION is not desirable, one may\r
2aa62f2b 360 * change the following to be a constant by:\r
361 * #define _LIB_VERSION_TYPE const enum version\r
362 * In that case, after one initializes the value _LIB_VERSION (see\r
363 * s_lib_version.c) during compile time, it cannot be modified\r
364 * in the middle of a program\r
365 */\r
366extern _LIB_VERSION_TYPE _LIB_VERSION;\r
367\r
368#define _IEEE_ fdlibm_ieee\r
369#define _SVID_ fdlibm_svid\r
370#define _XOPEN_ fdlibm_xopen\r
371#define _POSIX_ fdlibm_posix\r
372\r
373#ifndef __cplusplus\r
374struct exception {\r
375 int type;\r
376 char *name;\r
377 double arg1;\r
378 double arg2;\r
379 double retval;\r
380};\r
381#endif\r
382\r
383#define HUGE MAXFLOAT\r
384\r
a430bdb1 385/** set X_TLOSS = pi*2**52 **/\r
2aa62f2b 386#define X_TLOSS 1.41484755040568800000e+16\r
387\r
388#define DOMAIN 1\r
389#define SING 2\r
390#define OVERFLOW 3\r
391#define UNDERFLOW 4\r
392#define TLOSS 5\r
393#define PLOSS 6\r
a430bdb1 394/*@}*/\r
2aa62f2b 395\r
a430bdb1 396/* 7.12#4 INFINITY */\r
397#ifdef __INFINITY\r
398#define INFINITY __INFINITY /**< float constant which overflows */\r
2aa62f2b 399#else\r
a430bdb1 400#define INFINITY HUGE_VALF /**< positive infinity */\r
401#endif /* __INFINITY */\r
2aa62f2b 402\r
a430bdb1 403/* 7.12#5 NAN: a quiet NaN, if supported */\r
404#ifdef __HAVE_NANF\r
405extern const union __float_u __nanf;\r
406#define NAN __nanf.__val\r
407#endif /* __HAVE_NANF */\r
2aa62f2b 408\r
a430bdb1 409/**@{\r
410 C99 7.12#6 Number classification macros represent mutually exclusive kinds of floating-point\r
411 values.\r
412**/\r
413#define FP_INFINITE 0x00\r
414#define FP_NAN 0x01\r
415#define FP_NORMAL 0x02\r
416#define FP_SUBNORMAL 0x03\r
417#define FP_ZERO 0x04\r
418/* NetBSD extensions */\r
419#define _FP_LOMD 0x80 /**< range for machine-specific classes */\r
420#define _FP_HIMD 0xff\r
421/*@)*/\r
2aa62f2b 422\r
a430bdb1 423/**@{\r
424 * Constants ala XOPEN/SVID.\r
2aa62f2b 425 */\r
a430bdb1 426#define M_E 2.7182818284590452354 /**< e */\r
427#define M_LOG2E 1.4426950408889634074 /**< log 2e */\r
428#define M_LOG10E 0.43429448190325182765 /**< log 10e */\r
429#define M_LN2 0.69314718055994530942 /**< log e2 */\r
430#define M_LN10 2.30258509299404568402 /**< log e10 */\r
431#define M_PI 3.14159265358979323846 /**< pi */\r
432#define M_PI_2 1.57079632679489661923 /**< pi/2 */\r
433#define M_PI_4 0.78539816339744830962 /**< pi/4 */\r
434#define M_1_PI 0.31830988618379067154 /**< 1/pi */\r
435#define M_2_PI 0.63661977236758134308 /**< 2/pi */\r
436#define M_2_SQRTPI 1.12837916709551257390 /**< 2/sqrt(pi) */\r
437#define M_SQRT2 1.41421356237309504880 /**< sqrt(2) */\r
438#define M_SQRT1_2 0.70710678118654752440 /**< 1/sqrt(2) */\r
439#define MAXFLOAT ((float)3.40282346638528860e+38)\r
440/*@}*/\r
2aa62f2b 441\r
442#endif /* _MATH_H_ */\r