POK
/home/jaouen/pok_official/pok/trunk/libpok/libm/e_sinh.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Fri Jan 30 14:41:34 2009 
00015  */
00016 
00017 /* @(#)e_sinh.c 5.1 93/09/24 */
00018 /*
00019  * ====================================================
00020  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00021  *
00022  * Developed at SunPro, a Sun Microsystems, Inc. business.
00023  * Permission to use, copy, modify, and distribute this
00024  * software is freely granted, provided that this notice
00025  * is preserved.
00026  * ====================================================
00027  */
00028 
00029 /* __ieee754_sinh(x)
00030  * Method :
00031  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
00032  *      1. Replace x by |x| (sinh(-x) = -sinh(x)).
00033  *      2.
00034  *                                                  E + E/(E+1)
00035  *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
00036  *                                                      2
00037  *
00038  *          22       <= x <= lnovft :  sinh(x) := exp(x)/2
00039  *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
00040  *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
00041  *
00042  * Special cases:
00043  *      sinh(x) is |x| if x is +INF, -INF, or NaN.
00044  *      only sinh(0)=0 is exact for finite x.
00045  */
00046 
00047 #ifdef POK_NEEDS_LIBMATH
00048 
00049 #include <libm.h>
00050 #include "math_private.h"
00051 
00052 static const double one = 1.0, shuge = 1.0e307;
00053 
00054 double
00055 __ieee754_sinh(double x)
00056 {
00057         double t,w,h;
00058         int32_t ix,jx;
00059         uint32_t lx;
00060 
00061     /* High word of |x|. */
00062         GET_HIGH_WORD(jx,x);
00063         ix = jx&0x7fffffff;
00064 
00065     /* x is INF or NaN */
00066         if(ix>=0x7ff00000) return x+x;
00067 
00068         h = 0.5;
00069         if (jx<0) h = -h;
00070     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
00071         if (ix < 0x40360000) {          /* |x|<22 */
00072             if (ix<0x3e300000)          /* |x|<2**-28 */
00073                 if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
00074             t = expm1(fabs(x));
00075             if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
00076             return h*(t+t/(t+one));
00077         }
00078 
00079     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
00080         if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
00081 
00082     /* |x| in [log(maxdouble), overflowthresold] */
00083         GET_LOW_WORD(lx,x);
00084         if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d))) {
00085             w = __ieee754_exp(0.5*fabs(x));
00086             t = h*w;
00087             return t*w;
00088         }
00089 
00090     /* |x| > overflowthresold, sinh(x) overflow */
00091         return x*shuge;
00092 }
00093 #endif
00094