Home | History | Annotate | Line # | Download | only in src
      1 /* from: FreeBSD: head/lib/msun/src/e_acosh.c 176451 2008-02-22 02:30:36Z das */
      2 
      3 /*
      4  * ====================================================
      5  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      6  *
      7  * Developed at SunPro, a Sun Microsystems, Inc. business.
      8  * Permission to use, copy, modify, and distribute this
      9  * software is freely granted, provided that this notice
     10  * is preserved.
     11  * ====================================================
     12  */
     13 
     14 #include <sys/cdefs.h>
     15 
     16 #include "namespace.h"
     17 
     18 #include <float.h>
     19 #include <machine/ieee.h>
     20 
     21 #include "math.h"
     22 #include "math_private.h"
     23 
     24 __weak_alias(asinhl, _asinhl)
     25 
     26 #ifdef __HAVE_LONG_DOUBLE
     27 
     28 /*
     29  * See s_asinh.c for complete comments.
     30  *
     31  * Converted to long double by David Schultz <das (at) FreeBSD.ORG> and
     32  * Bruce D. Evans.
     33  */
     34 
     35 /* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */
     36 /* EXP_TINY is the threshold below which we use asinh(x) ~= x. */
     37 #if LDBL_MANT_DIG == 64
     38 #define	EXP_LARGE	34
     39 #define	EXP_TINY	-34
     40 #elif LDBL_MANT_DIG == 113
     41 #define	EXP_LARGE	58
     42 #define	EXP_TINY	-58
     43 #else
     44 #error "Unsupported long double format"
     45 #endif
     46 
     47 #if LDBL_MAX_EXP != 0x4000
     48 /* We also require the usual expsign encoding. */
     49 #error "Unsupported long double format"
     50 #endif
     51 
     52 #define	BIAS	(LDBL_MAX_EXP - 1)
     53 
     54 static const double
     55 one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
     56 huge=  1.00000000000000000000e+300;
     57 
     58 #if LDBL_MANT_DIG == 64
     59 static const union ieee_ext_u
     60 u_ln2 =  LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
     61 #define	ln2	u_ln2.extu_ld
     62 #elif LDBL_MANT_DIG == 113
     63 static const long double
     64 ln2 =  6.93147180559945309417232121458176568e-1L;	/* 0x162e42fefa39ef35793c7673007e6.0p-113 */
     65 #else
     66 #error "Unsupported long double format"
     67 #endif
     68 
     69 long double
     70 asinhl(long double x)
     71 {
     72 	long double t, w;
     73 	uint16_t hx, ix;
     74 
     75 	ENTERI();
     76 	GET_LDBL_EXPSIGN(hx, x);
     77 	ix = hx & 0x7fff;
     78 	if (ix >= 0x7fff) RETURNI(x+x);	/* x is inf, NaN or misnormal */
     79 	if (ix < BIAS + EXP_TINY) {	/* |x| < TINY, or misnormal */
     80 	    if (huge + x > one) RETURNI(x);	/* return x inexact except 0 */
     81 	}
     82 	if (ix >= BIAS + EXP_LARGE) {	/* |x| >= LARGE, or misnormal */
     83 	    w = logl(fabsl(x))+ln2;
     84 	} else if (ix >= 0x4000) {	/* LARGE > |x| >= 2.0, or misnormal */
     85 	    t = fabsl(x);
     86 	    w = logl(2.0*t+one/(sqrtl(x*x+one)+t));
     87 	} else {		/* 2.0 > |x| >= TINY, or misnormal */
     88 	    t = x*x;
     89 	    w =log1pl(fabsl(x)+t/(one+sqrtl(one+t)));
     90 	}
     91 	RETURNI((hx & 0x8000) == 0 ? w : -w);
     92 }
     93 #else
     94 long double
     95 asinhl(long double x)
     96 {
     97 	return asinh(x);
     98 }
     99 #endif
    100