GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libm/src/e_atanh.c Lines: 12 14 85.7 %
Date: 2017-11-13 Branches: 9 12 75.0 %

Line Branch Exec Source
1
/* @(#)e_atanh.c 5.1 93/09/24 */
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
/* atanh(x)
14
 * Method :
15
 *    1.Reduced x to positive by atanh(-x) = -atanh(x)
16
 *    2.For x>=0.5
17
 *                  1              2x                          x
18
 *	atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
19
 *                  2             1 - x                      1 - x
20
 *
21
 * 	For x<0.5
22
 *	atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
23
 *
24
 * Special cases:
25
 *	atanh(x) is NaN if |x| > 1 with signal;
26
 *	atanh(NaN) is that NaN with no signal;
27
 *	atanh(+-1) is +-INF with signal.
28
 *
29
 */
30
31
#include <float.h>
32
#include <math.h>
33
34
#include "math_private.h"
35
36
static const double one = 1.0, huge = 1e300;
37
static const double zero = 0.0;
38
39
double
40
atanh(double x)
41
{
42
	double t;
43
	int32_t hx,ix;
44
	u_int32_t lx;
45
11916
	EXTRACT_WORDS(hx,lx,x);
46
5958
	ix = hx&0x7fffffff;
47
5958
	if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
48
	    return (x-x)/(x-x);
49
5958
	if(ix==0x3ff00000)
50
	    return x/zero;
51

6822
	if(ix<0x3e300000&&(huge+x)>zero) return x;	/* x<2**-28 */
52
5526
	SET_HIGH_WORD(x,ix);
53
5526
	if(ix<0x3fe00000) {		/* x < 0.5 */
54
	    t = x+x;
55
1476
	    t = 0.5*log1p(t+t*x/(one-x));
56
1476
	} else
57
4050
	    t = 0.5*log1p((x+x)/(one-x));
58
11052
	if(hx>=0) return t; else return -t;
59
5958
}
60
DEF_STD(atanh);
61
LDBL_MAYBE_UNUSED_CLONE(atanh);