]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/Math/e_sinh.c
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / LibC / Math / e_sinh.c
diff --git a/StdLib/LibC/Math/e_sinh.c b/StdLib/LibC/Math/e_sinh.c
new file mode 100644 (file)
index 0000000..421b515
--- /dev/null
@@ -0,0 +1,79 @@
+/* @(#)e_sinh.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_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");\r
+#endif\r
+\r
+#include "math.h"\r
+#include "math_private.h"\r
+\r
+/* __ieee754_sinh(x)\r
+ * Method :\r
+ * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2\r
+ *  1. Replace x by |x| (sinh(-x) = -sinh(x)).\r
+ *  2.\r
+ *                                        E + E/(E+1)\r
+ *      0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)\r
+ *                          2\r
+ *\r
+ *      22       <= x <= lnovft :  sinh(x) := exp(x)/2\r
+ *      lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)\r
+ *      ln2ovft  <  x     :  sinh(x) := x*shuge (overflow)\r
+ *\r
+ * Special cases:\r
+ *  sinh(x) is |x| if x is +INF, -INF, or NaN.\r
+ *  only sinh(0)=0 is exact for finite x.\r
+ */\r
+\r
+static const double one = 1.0, shuge = 1.0e307;\r
+\r
+double\r
+__ieee754_sinh(double x)\r
+{\r
+  double t,w,h;\r
+  int32_t ix,jx;\r
+  u_int32_t lx;\r
+\r
+    /* High word of |x|. */\r
+  GET_HIGH_WORD(jx,x);\r
+  ix = jx&0x7fffffff;\r
+\r
+    /* x is INF or NaN */\r
+  if(ix>=0x7ff00000) return x+x;\r
+\r
+  h = 0.5;\r
+  if (jx<0) h = -h;\r
+    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */\r
+  if (ix < 0x40360000) {    /* |x|<22 */\r
+      if (ix<0x3e300000)    /* |x|<2**-28 */\r
+    if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */\r
+      t = expm1(fabs(x));\r
+      if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));\r
+      return h*(t+t/(t+one));\r
+  }\r
+\r
+    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */\r
+  if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));\r
+\r
+    /* |x| in [log(maxdouble), overflowthresold] */\r
+  GET_LOW_WORD(lx,x);\r
+  if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {\r
+      w = __ieee754_exp(0.5*fabs(x));\r
+      t = h*w;\r
+      return t*w;\r
+  }\r
+\r
+    /* |x| > overflowthresold, sinh(x) overflow */\r
+  return x*shuge;\r
+}\r