1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<h1 id="firstHeading" class="firstHeading">tanh, tanhf, tanhl</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><math.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">float tanhf( float arg );</pre>
</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl"> <td> <pre data-language="c">double tanh( double arg );</pre>
</td> <td> (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">long double tanhl( long double arg );</pre>
</td> <td> (3) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dsc-header"> <th> Defined in header <code><tgmath.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define tanh( arg )</pre>
</td> <td> (4) </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <div class="t-li1">
<span class="t-li">1-3)</span> Computes the hyperbolic tangent of <code>arg</code>.</div> <div class="t-li1">
<span class="t-li">4)</span> Type-generic macro: If the argument has type <code>long double</code>, <code>tanhl</code> is called. Otherwise, if the argument has integer type or the type <code>double</code>, <code>tanh</code> is called. Otherwise, <code>tanhf</code> is called. If the argument is complex, then the macro invokes the corresponding complex function (<code><a href="http://en.cppreference.com/w/c/numeric/complex/ctanh"><span class="kw814">ctanhf</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/ctanh"><span class="kw813">ctanh</span></a></code>, <code><a href="http://en.cppreference.com/w/c/numeric/complex/ctanh"><span class="kw815">ctanhl</span></a></code>).</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value representing a hyperbolic angle </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> If no errors occur, the hyperbolic tangent of <code>arg</code> (tanh(arg), or <span><span>earg-e-arg</span><span>/</span><span>earg+e-arg</span></span>) is returned. <p>If a range error occurs due to underflow, the correct result (after rounding) is returned.</p>
<h3 id="Error_handling"> Error handling</h3> <p>Errors are reported as specified in <a href="math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a>.</p>
<p>If the implementation supports IEEE floating-point arithmetic (IEC 60559),</p>
<ul>
<li> if the argument is ±0, ±0 is returned </li>
<li> If the argument is ±∞, ±1 is returned </li>
<li> if the argument is NaN, NaN is returned </li>
</ul> <h3 id="Notes"> Notes</h3> <p><a rel="nofollow" class="external text" href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/tanh.html">POSIX specifies</a> that in case of underflow, <code>arg</code> is returned unmodified, and if that is not supported, an implementation-defined value no greater than DBL_MIN, FLT_MIN, and LDBL_MIN is returned.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h>
#include <math.h>
int main(void)
{
printf("tanh(1) = %f\ntanh(-1) = %f\n", tanh(1), tanh(-1));
printf("tanh(0.1)*sinh(0.2)-cosh(0.2) = %f\n", tanh(0.1) * sinh(0.2) - cosh(0.2));
// special values
printf("tanh(+0) = %f\ntanh(-0) = %f\n", tanh(0.0), tanh(-0.0));
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">tanh(1) = 0.761594
tanh(-1) = -0.761594
tanh(0.1)*sinh(0.2)-cosh(0.2) = -1.000000
tanh(+0) = 0.000000
tanh(-0) = -0.000000</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul>
<li> 7.12.5.6 The tanh functions (p: 242) </li>
<li> 7.25 Type-generic math <tgmath.h> (p: 373-375) </li>
<li> F.10.2.6 The tanh functions (p: 520) </li>
</ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul>
<li> 7.12.5.6 The tanh functions (p: 222-223) </li>
<li> 7.22 Type-generic math <tgmath.h> (p: 335-337) </li>
<li> F.9.2.6 The tanh functions (p: 457) </li>
</ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.5.3.3 The tanh function </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="sinh" title="c/numeric/math/sinh"> <span class="t-lines"><span>sinh</span><span>sinhf</span><span>sinhl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes hyperbolic sine (\({\small\sinh{x} }\)sinh(x)) <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="cosh" title="c/numeric/math/cosh"> <span class="t-lines"><span>cosh</span><span>coshf</span><span>coshl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes hyperbolic cosine (\({\small\cosh{x} }\)cosh(x)) <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="atanh" title="c/numeric/math/atanh"> <span class="t-lines"><span>atanh</span><span>atanhf</span><span>atanhl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes inverse hyperbolic tangent (\({\small\operatorname{artanh}{x} }\)artanh(x)) <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="../complex/ctanh" title="c/numeric/complex/ctanh"> <span class="t-lines"><span>ctanh</span><span>ctanhf</span><span>ctanhl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes the complex hyperbolic tangent <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/tanh" title="cpp/numeric/math/tanh">C++ documentation</a></span> for <code>tanh</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/numeric/math/tanh" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/tanh</a>
</p>
</div>
|