Back to index

lightning-sunbird  0.9+nobinonly
e_sinh.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Sun Microsystems, Inc.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /* @(#)e_sinh.c 1.3 95/01/18 */
00041 /*
00042  * ====================================================
00043  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00044  *
00045  * Developed at SunSoft, a Sun Microsystems, Inc. business.
00046  * Permission to use, copy, modify, and distribute this
00047  * software is freely granted, provided that this notice 
00048  * is preserved.
00049  * ====================================================
00050  */
00051 
00052 /* __ieee754_sinh(x)
00053  * Method : 
00054  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
00055  *     1. Replace x by |x| (sinh(-x) = -sinh(x)). 
00056  *     2. 
00057  *                                                E + E/(E+1)
00058  *         0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
00059  *                                                       2
00060  *
00061  *         22       <= x <= lnovft :  sinh(x) := exp(x)/2 
00062  *         lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
00063  *         ln2ovft  <  x        :  sinh(x) := x*shuge (overflow)
00064  *
00065  * Special cases:
00066  *     sinh(x) is |x| if x is +INF, -INF, or NaN.
00067  *     only sinh(0)=0 is exact for finite x.
00068  */
00069 
00070 #include "fdlibm.h"
00071 
00072 #ifdef __STDC__
00073 static const double one = 1.0, shuge = 1.0e307;
00074 #else
00075 static double one = 1.0, shuge = 1.0e307;
00076 #endif
00077 
00078 #ifdef __STDC__
00079        double __ieee754_sinh(double x)
00080 #else
00081        double __ieee754_sinh(x)
00082        double x;
00083 #endif
00084 {      
00085         fd_twoints u;
00086        double t,w,h;
00087        int ix,jx;
00088        unsigned lx;
00089 
00090     /* High word of |x|. */
00091         u.d = x;
00092        jx = __HI(u);
00093        ix = jx&0x7fffffff;
00094 
00095     /* x is INF or NaN */
00096        if(ix>=0x7ff00000) return x+x;     
00097 
00098        h = 0.5;
00099        if (jx<0) h = -h;
00100     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
00101        if (ix < 0x40360000) {             /* |x|<22 */
00102            if (ix<0x3e300000)             /* |x|<2**-28 */
00103               if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
00104            t = fd_expm1(fd_fabs(x));
00105            if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
00106            return h*(t+t/(t+one));
00107        }
00108 
00109     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
00110        if (ix < 0x40862E42)  return h*__ieee754_exp(fd_fabs(x));
00111 
00112     /* |x| in [log(maxdouble), overflowthresold] */
00113        lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
00114        if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) {
00115            w = __ieee754_exp(0.5*fd_fabs(x));
00116            t = h*w;
00117            return t*w;
00118        }
00119 
00120     /* |x| > overflowthresold, sinh(x) overflow */
00121        return x*shuge;
00122 }