Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. /* s_tanhf.c -- float version of s_tanh.c.
  3.  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
  4.  */
  5.  
  6. /*
  7.  * ====================================================
  8.  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  9.  *
  10.  * Developed at SunPro, a Sun Microsystems, Inc. business.
  11.  * Permission to use, copy, modify, and distribute this
  12.  * software is freely granted, provided that this notice
  13.  * is preserved.
  14.  * ====================================================
  15.  */
  16.  
  17. #if defined(LIBM_SCCS) && !defined(lint)
  18. static char rcsid[] = "$Id: s_tanhf.c,v 1.2 1994/08/18 23:10:23 jtc Exp $";
  19. #endif
  20.  
  21. #include "math.h"
  22. #include "math_private.h"
  23.  
  24. #ifdef __STDC__
  25. static const float one=1.0, two=2.0, tiny = 1.0e-30;
  26. #else
  27. static float one=1.0, two=2.0, tiny = 1.0e-30;
  28. #endif
  29.  
  30. #ifdef __STDC__
  31.         float tanhf(float x)
  32. #else
  33.         float tanhf(x)
  34.         float x;
  35. #endif
  36. {
  37.         float t,z;
  38.         int32_t jx,ix;
  39.  
  40.         GET_FLOAT_WORD(jx,x);
  41.         ix = jx&0x7fffffff;
  42.  
  43.     /* x is INF or NaN */
  44.         if(ix>=0x7f800000) {
  45.             if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
  46.             else       return one/x-one;    /* tanh(NaN) = NaN */
  47.         }
  48.  
  49.     /* |x| < 22 */
  50.         if (ix < 0x41b00000) {          /* |x|<22 */
  51.             if (ix<0x24000000)          /* |x|<2**-55 */
  52.                 return x*(one+x);       /* tanh(small) = small */
  53.             if (ix>=0x3f800000) {       /* |x|>=1  */
  54.                 t = expm1f(two*fabsf(x));
  55.                 z = one - two/(t+two);
  56.             } else {
  57.                 t = expm1f(-two*fabsf(x));
  58.                 z= -t/(t+two);
  59.             }
  60.     /* |x| > 22, return +-1 */
  61.         } else {
  62.             z = one - tiny;             /* raised inexact flag */
  63.         }
  64.         return (jx>=0)? z: -z;
  65. }
  66.