]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/Math/e_exp.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / LibC / Math / e_exp.c
diff --git a/StdLib/LibC/Math/e_exp.c b/StdLib/LibC/Math/e_exp.c
deleted file mode 100644 (file)
index f05f539..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* @(#)e_exp.c 5.1 93/09/24 */\r
-/*\r
- * ====================================================\r
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
- *\r
- * Developed at SunPro, a Sun Microsystems, Inc. business.\r
- * Permission to use, copy, modify, and distribute this\r
- * software is freely granted, provided that this notice\r
- * is preserved.\r
- * ====================================================\r
- */\r
-#include  <LibConfig.h>\r
-#include  <sys/EfiCdefs.h>\r
-#if defined(LIBM_SCCS) && !defined(lint)\r
-__RCSID("$NetBSD: e_exp.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");\r
-#endif\r
-\r
-#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */\r
-  // C4756: overflow in constant arithmetic\r
-  #pragma warning ( disable : 4756 )\r
-#endif\r
-\r
-/* __ieee754_exp(x)\r
- * Returns the exponential of x.\r
- *\r
- * Method\r
- *   1. Argument reduction:\r
- *      Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.\r
- *  Given x, find r and integer k such that\r
- *\r
- *               x = k*ln2 + r,  |r| <= 0.5*ln2.\r
- *\r
- *      Here r will be represented as r = hi-lo for better\r
- *  accuracy.\r
- *\r
- *   2. Approximation of exp(r) by a special rational function on\r
- *  the interval [0,0.34658]:\r
- *  Write\r
- *      R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...\r
- *      We use a special Reme algorithm on [0,0.34658] to generate\r
- *  a polynomial of degree 5 to approximate R. The maximum error\r
- *  of this polynomial approximation is bounded by 2**-59. In\r
- *  other words,\r
- *      R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5\r
- *    (where z=r*r, and the values of P1 to P5 are listed below)\r
- *  and\r
- *      |                  5          |     -59\r
- *      | 2.0+P1*z+...+P5*z   -  R(z) | <= 2\r
- *      |                             |\r
- *  The computation of exp(r) thus becomes\r
- *                             2*r\r
- *    exp(r) = 1 + -------\r
- *                  R - r\r
- *                                 r*R1(r)\r
- *           = 1 + r + ----------- (for better accuracy)\r
- *                      2 - R1(r)\r
- *  where\r
- *               2       4             10\r
- *    R1(r) = r - (P1*r  + P2*r  + ... + P5*r   ).\r
- *\r
- *   3. Scale back to obtain exp(x):\r
- *  From step 1, we have\r
- *     exp(x) = 2^k * exp(r)\r
- *\r
- * Special cases:\r
- *  exp(INF) is INF, exp(NaN) is NaN;\r
- *  exp(-INF) is 0, and\r
- *  for finite argument, only exp(0)=1 is exact.\r
- *\r
- * Accuracy:\r
- *  according to an error analysis, the error is always less than\r
- *  1 ulp (unit in the last place).\r
- *\r
- * Misc. info.\r
- *  For IEEE double\r
- *      if x >  7.09782712893383973096e+02 then exp(x) overflow\r
- *      if x < -7.45133219101941108420e+02 then exp(x) underflow\r
- *\r
- * Constants:\r
- * The hexadecimal values are the intended ones for the following\r
- * constants. The decimal values may be used, provided that the\r
- * compiler will convert from decimal to binary accurately enough\r
- * to produce the hexadecimal values shown.\r
- */\r
-\r
-#include "math.h"\r
-#include "math_private.h"\r
-\r
-static const double\r
-one = 1.0,\r
-halF[2] = {0.5,-0.5,},\r
-huge  = 1.0e+300,\r
-twom1000= 9.33263618503218878990e-302,     /* 2**-1000=0x01700000,0*/\r
-o_threshold=  7.09782712893383973096e+02,  /* 0x40862E42, 0xFEFA39EF */\r
-u_threshold= -7.45133219101941108420e+02,  /* 0xc0874910, 0xD52D3051 */\r
-ln2HI[2]   ={ 6.93147180369123816490e-01,  /* 0x3fe62e42, 0xfee00000 */\r
-       -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */\r
-ln2LO[2]   ={ 1.90821492927058770002e-10,  /* 0x3dea39ef, 0x35793c76 */\r
-       -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */\r
-invln2 =  1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */\r
-P1   =  1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */\r
-P2   = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */\r
-P3   =  6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */\r
-P4   = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */\r
-P5   =  4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */\r
-\r
-\r
-double\r
-__ieee754_exp(double x) /* default IEEE double exp */\r
-{\r
-  double y,hi,lo,c,t;\r
-  int32_t k,xsb;\r
-  u_int32_t hx;\r
-\r
-  hi = lo = 0;\r
-  k = 0;\r
-  GET_HIGH_WORD(hx,x);\r
-  xsb = (hx>>31)&1;   /* sign bit of x */\r
-  hx &= 0x7fffffff;   /* high word of |x| */\r
-\r
-    /* filter out non-finite argument */\r
-  if(hx >= 0x40862E42) {      /* if |x|>=709.78... */\r
-            if(hx>=0x7ff00000) {\r
-          u_int32_t lx;\r
-    GET_LOW_WORD(lx,x);\r
-    if(((hx&0xfffff)|lx)!=0)\r
-         return x+x;    /* NaN */\r
-    else return (xsb==0)? x:0.0;  /* exp(+-inf)={inf,0} */\r
-      }\r
-      if(x > o_threshold) return huge*huge; /* overflow */\r
-      if(x < u_threshold) return twom1000*twom1000; /* underflow */\r
-  }\r
-\r
-    /* argument reduction */\r
-  if(hx > 0x3fd62e42) {   /* if  |x| > 0.5 ln2 */\r
-      if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */\r
-    hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;\r
-      } else {\r
-    k  = (int32_t)(invln2*x+halF[xsb]);\r
-    t  = k;\r
-    hi = x - t*ln2HI[0];  /* t*ln2HI is exact here */\r
-    lo = t*ln2LO[0];\r
-      }\r
-      x  = hi - lo;\r
-  }\r
-  else if(hx < 0x3e300000)  { /* when |x|<2**-28 */\r
-      if(huge+x>one) return one+x;/* trigger inexact */\r
-  }\r
-  else k = 0;\r
-\r
-    /* x is now in primary range */\r
-  t  = x*x;\r
-  c  = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));\r
-  if(k==0)  return one-((x*c)/(c-2.0)-x);\r
-  else    y = one-((lo-(x*c)/(2.0-c))-hi);\r
-  if(k >= -1021) {\r
-      u_int32_t hy;\r
-      GET_HIGH_WORD(hy,y);\r
-      SET_HIGH_WORD(y,hy+(k<<20));  /* add k to y's exponent */\r
-      return y;\r
-  } else {\r
-      u_int32_t hy;\r
-      GET_HIGH_WORD(hy,y);\r
-      SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */\r
-      return y*twom1000;\r
-  }\r
-}\r