1  /* e_sinhl.c -- long double version of e_sinh.c.
       2   */
       3  
       4  /*
       5   * ====================================================
       6   * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
       7   *
       8   * Developed at SunPro, a Sun Microsystems, Inc. business.
       9   * Permission to use, copy, modify, and distribute this
      10   * software is freely granted, provided that this notice
      11   * is preserved.
      12   * ====================================================
      13   */
      14  
      15  /* Changes for 128-bit long double are
      16     Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
      17     and are incorporated herein by permission of the author.  The author
      18     reserves the right to distribute this material elsewhere under different
      19     copying permissions.  These modifications are distributed here under
      20     the following terms:
      21  
      22      This library is free software; you can redistribute it and/or
      23      modify it under the terms of the GNU Lesser General Public
      24      License as published by the Free Software Foundation; either
      25      version 2.1 of the License, or (at your option) any later version.
      26  
      27      This library is distributed in the hope that it will be useful,
      28      but WITHOUT ANY WARRANTY; without even the implied warranty of
      29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      30      Lesser General Public License for more details.
      31  
      32      You should have received a copy of the GNU Lesser General Public
      33      License along with this library; if not, see
      34      <https://www.gnu.org/licenses/>.  */
      35  
      36  /* __ieee754_sinhl(x)
      37   * Method :
      38   * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
      39   *      1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
      40   *      2.
      41   *                                                   E + E/(E+1)
      42   *          0        <= x <= 25     :  sinhl(x) := --------------, E=expm1l(x)
      43   *                                                       2
      44   *
      45   *          25       <= x <= lnovft :  sinhl(x) := expl(x)/2
      46   *          lnovft   <= x <= ln2ovft:  sinhl(x) := expl(x/2)/2 * expl(x/2)
      47   *          ln2ovft  <  x           :  sinhl(x) := x*shuge (overflow)
      48   *
      49   * Special cases:
      50   *      sinhl(x) is |x| if x is +INF, -INF, or NaN.
      51   *      only sinhl(0)=0 is exact for finite x.
      52   */
      53  
      54  #include <float.h>
      55  #include <math.h>
      56  #include <math_private.h>
      57  #include <math-underflow.h>
      58  #include <libm-alias-finite.h>
      59  
      60  static const _Float128 one = 1.0, shuge = L(1.0e4931),
      61  ovf_thresh = L(1.1357216553474703894801348310092223067821E4);
      62  
      63  _Float128
      64  __ieee754_sinhl (_Float128 x)
      65  {
      66    _Float128 t, w, h;
      67    uint32_t jx, ix;
      68    ieee854_long_double_shape_type u;
      69  
      70    /* Words of |x|. */
      71    u.value = x;
      72    jx = u.parts32.w0;
      73    ix = jx & 0x7fffffff;
      74  
      75    /* x is INF or NaN */
      76    if (ix >= 0x7fff0000)
      77      return x + x;
      78  
      79    h = 0.5;
      80    if (jx & 0x80000000)
      81      h = -h;
      82  
      83    /* Absolute value of x.  */
      84    u.parts32.w0 = ix;
      85  
      86    /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
      87    if (ix <= 0x40044000)
      88      {
      89        if (ix < 0x3fc60000) /* |x| < 2^-57 */
      90  	{
      91  	  math_check_force_underflow (x);
      92  	  if (shuge + x > one)
      93  	    return x;		/* sinh(tiny) = tiny with inexact */
      94  	}
      95        t = __expm1l (u.value);
      96        if (ix < 0x3fff0000)
      97  	return h * (2.0 * t - t * t / (t + one));
      98        return h * (t + t / (t + one));
      99      }
     100  
     101    /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
     102    if (ix <= 0x400c62e3) /* 11356.375 */
     103      return h * __ieee754_expl (u.value);
     104  
     105    /* |x| in [log(maxdouble), overflowthreshold]
     106       Overflow threshold is log(2 * maxdouble).  */
     107    if (u.value <= ovf_thresh)
     108      {
     109        w = __ieee754_expl (0.5 * u.value);
     110        t = h * w;
     111        return t * w;
     112      }
     113  
     114    /* |x| > overflowthreshold, sinhl(x) overflow */
     115    return x * shuge;
     116  }
     117  libm_alias_finite (__ieee754_sinhl, __sinhl)