amath  1.6.2
Simple command line calculator
asinh.c
Go to the documentation of this file.
1 /* @(#)s_asinh.c 1.3 95/01/18 */
2 
3 /*
4  * Copyright (c) 2015-2017 Carsten Sonne Larsen <cs@innolan.dk>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * The origin source code can be obtained from:
28  * http://www.netlib.org/fdlibm/s_asinh.c
29  *
30  */
31 
32 /*
33  * ====================================================
34  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
35  *
36  * Developed at SunSoft, a Sun Microsystems, Inc. business.
37  * Permission to use, copy, modify, and distribute this
38  * software is freely granted, provided that this notice
39  * is preserved.
40  * ====================================================
41  *
42  */
43 
44 #include "prim.h"
45 #include "math.h"
46 
47 static const double
48 one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
49 ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
50 huge= 1.00000000000000000000e+300;
51 
52 /**
53  * @brief Inverse hyperbolic sine function.
54  * @version 1.3
55  * @date 95/01/18
56  * @details
57  * <pre>
58  * Method :
59  * Based on
60  * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
61  * we have
62  * asinh(x) := x if 1+x*x=1,
63  * := sign(x)*(log(x)+ln2)) for large |x|, else
64  * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
65  * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
66  * </pre>
67  * @copyright Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
68  * @license Developed at SunSoft, a Sun Microsystems, Inc. business. Permission
69  * to use, copy, modify, and distribute this software is freely granted,
70  * provided that this notice is preserved.
71  */
72 
73 double asinh(double x)
74 {
75  double t,w;
76  sword hx,ix;
77  GET_HIGH_WORD(hx,x);
78  ix = hx&0x7fffffff;
79  if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
80  if(ix< 0x3e300000) { /* |x|<2**-28 */
81  if(huge+x>one) return x; /* return x inexact except 0 */
82  }
83  if(ix>0x41b00000) { /* |x| > 2**28 */
84  w = log(fabs(x))+ln2;
85  } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
86  t = fabs(x);
87  w = log(2.0*t+one/(sqrt(x*x+one)+t));
88  } else { /* 2.0 > |x| > 2**-28 */
89  t = x*x;
90  w =log1p(fabs(x)+t/(one+sqrt(one+t)));
91  }
92  if(hx>0) return w;
93  else return -w;
94 }
double sqrt(double x)
Square root function.
Definition: sqrt.c:127
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:165
double log1p(double x)
Definition: log1p.c:125
signed int sword
32 bit signed integer.
Definition: prim.h:107
static const double ln2
Definition: asinh.c:49
static const double huge
Definition: asinh.c:50
static const double one
Definition: asinh.c:48
double asinh(double x)
Inverse hyperbolic sine function.
Definition: asinh.c:73