1 /*
2  * Copyright (C) 1999, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011,
3  * 2012, 2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU libmatheval
6  *
7  * GNU libmatheval is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * GNU libmatheval is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU libmatheval.  If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "xmath.h"
23 
24 double
math_cot(double x)25 math_cot(double x)
26 {
27 	/*
28 	 * Calculate cotangent value.
29 	 */
30 	return 1 / tan(x);
31 }
32 
33 double
math_sec(double x)34 math_sec(double x)
35 {
36 	/*
37 	 * Calculate secant value.
38 	 */
39 	return 1 / cos(x);
40 }
41 
42 double
math_csc(double x)43 math_csc(double x)
44 {
45 	/*
46 	 * Calculate cosecant value.
47 	 */
48 	return 1 / sin(x);
49 }
50 
51 double
math_acot(double x)52 math_acot(double x)
53 {
54 	/*
55 	 * Calculate inverse cotangent value.
56 	 */
57 	return atan(1 / x);
58 }
59 
60 double
math_asec(double x)61 math_asec(double x)
62 {
63 	/*
64 	 * Calculate inverse secant value.
65 	 */
66 	return acos(1 / x);
67 }
68 
69 double
math_acsc(double x)70 math_acsc(double x)
71 {
72 	/*
73 	 * Calculate inverse cosecant value.
74 	 */
75 	return asin(1 / x);
76 }
77 
78 double
math_coth(double x)79 math_coth(double x)
80 {
81 	/*
82 	 * Calculate hyperbolic cotangent value.
83 	 */
84 	return 1 / tanh(x);
85 }
86 
87 double
math_sech(double x)88 math_sech(double x)
89 {
90 	/*
91 	 * Calculate hyperbolic secant value.
92 	 */
93 	return 1 / cosh(x);
94 }
95 
96 double
math_csch(double x)97 math_csch(double x)
98 {
99 	/*
100 	 * Calculate hyperbolic cosecant value.
101 	 */
102 	return 1 / sinh(x);
103 }
104 
105 double
math_asinh(double x)106 math_asinh(double x)
107 {
108 	/*
109 	 * Calculate inverse hyperbolic sine value.
110 	 */
111 	return log(x + sqrt(x * x + 1));
112 }
113 
114 double
math_acosh(double x)115 math_acosh(double x)
116 {
117 	/*
118 	 * Calculate inverse hyperbolic cosine value.
119 	 */
120 	return log(x + sqrt(x * x - 1));
121 }
122 
123 double
math_atanh(double x)124 math_atanh(double x)
125 {
126 	/*
127 	 * Calculate inverse hyperbolic tangent value.
128 	 */
129 	return 0.5 * log((1 + x) / (1 - x));
130 }
131 
132 double
math_acoth(double x)133 math_acoth(double x)
134 {
135 	/*
136 	 * Calculate inverse hyperbolic cotangent value.
137 	 */
138 	return 0.5 * log((x + 1) / (x - 1));
139 }
140 
141 double
math_asech(double x)142 math_asech(double x)
143 {
144 	/*
145 	 * Calculate inverse hyperbolic secant value.
146 	 */
147 	return math_acosh(1 / x);
148 }
149 
150 double
math_acsch(double x)151 math_acsch(double x)
152 {
153 	/*
154 	 * Calculate inverse hyperbolic cosecant value.
155 	 */
156 	return math_asinh(1 / x);
157 }
158 
159 double
math_step(double x)160 math_step(double x)
161 {
162 	/*
163 	 * Calculate step function value.
164 	 */
165 	return MATH_ISNAN(x) ? x : ((x < 0) ? 0 : 1);
166 }
167 
168 double
math_delta(double x)169 math_delta(double x)
170 {
171 	/*
172 	 * Calculate delta function value.
173 	 */
174 	return MATH_ISNAN(x) ? x : ((x == 0) ? MATH_INFINITY : 0);
175 }
176 
177 double
math_nandelta(double x)178 math_nandelta(double x)
179 {
180 	/*
181 	 * Calculate modified delta function value.
182 	 */
183 	return MATH_ISNAN(x) ? x : ((x == 0) ? MATH_NAN : 0);
184 }
185