home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / hobby / palmoon / palmoon.EXE / s_asinh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-16  |  2.0 KB  |  73 lines

  1. // 15 August 1997, Rick Huebner:  Small changes made to adapt for MathLib
  2.  
  3. /* @(#)s_asinh.c 5.1 93/09/24 */
  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. #if defined(LIBM_SCCS) && !defined(lint)
  16. static char rcsid[] = "$NetBSD: s_asinh.c,v 1.9 1995/05/12 04:57:37 jtc Exp $";
  17. #endif
  18.  
  19. /* asinh(x)
  20.  * Method :
  21.  *    Based on
  22.  *        asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
  23.  *    we have
  24.  *    asinh(x) := x  if  1+x*x=1,
  25.  *         := sign(x)*(log(x)+ln2)) for large |x|, else
  26.  *         := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
  27.  *         := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
  28.  */
  29.  
  30. #include "math.h"
  31. #include "math_private.h"
  32.  
  33. #ifdef __STDC__
  34. static const double
  35. #else
  36. static double
  37. #endif
  38. one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  39. ln2 =  6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
  40. huge=  1.00000000000000000000e+300;
  41.  
  42. #ifdef __STDC__
  43.     double __asinh(double x)
  44. #else
  45.     double __asinh(x)
  46.     double x;
  47. #endif
  48. {
  49.     double t,w;
  50.     int32_t hx,ix;
  51.     GET_HIGH_WORD(hx,x);
  52.     ix = hx&0x7fffffff;
  53.     if(ix>=0x7ff00000) return x+x;    /* x is inf or NaN */
  54.     if(ix< 0x3e300000) {    /* |x|<2**-28 */
  55.         if(huge+x>one) return x;    /* return x inexact except 0 */
  56.     }
  57.     if(ix>0x41b00000) {    /* |x| > 2**28 */
  58.         w = __ieee754_log(__fabs(x))+ln2;
  59.     } else if (ix>0x40000000) {    /* 2**28 > |x| > 2.0 */
  60.         t = __fabs(x);
  61.         w = __ieee754_log(2.0*t+one/(jumpto__ieee754_sqrt(x*x+one)+t));
  62.     } else {        /* 2.0 > |x| > 2**-28 */
  63.         t = x*x;
  64.         w =__log1p(__fabs(x)+t/(one+jumpto__ieee754_sqrt(one+t)));
  65.     }
  66.     if(hx>0) return w; else return -w;
  67. }
  68. weak_alias (__asinh, asinh)
  69. #ifdef NO_LONG_DOUBLE
  70. strong_alias (__asinh, __asinhl)
  71. weak_alias (__asinh, asinhl)
  72. #endif
  73.