std::tanh, std::tanhf, std::tanhl_C++中文网
| 定义于头文件 |
||
| (1) | ||
| float tanh ( float arg ); |
||
| float tanhf( float arg ); |
(C++11 起) | |
| double tanh ( double arg ); |
(2) | |
| (3) | ||
| long double tanh ( long double arg ); |
||
| long double tanhl( long double arg ); |
(C++11 起) | |
| double tanh ( IntegralType arg ); |
(4) | (C++11 起) |
1-3) 计算 arg 的双曲正切。
4) 接受任何整数类型参数的重载集或函数模板。等价于 2) (将参数转型为 double )。
参数
返回值
若不出现错误,则返回 arg 的双曲正切( tanh(arg) 或 )。
若发生下溢所致的错误,则返回(舍入后的)正确结果。
错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点算术( IEC 60559 ),则
- 若参数为 ±0 ,则返回 ±0
- 若参数为 ±∞ ,则返回 ±1
- 若参数为 NaN ,则返回 NaN
注意
POSIX 指定在下溢的情况中,返回不修改的 arg ,而且若不支持这么做,则返回不大于 DBL_MIN 、 FLT_MIN 和 LDBL_MIN 的实现定义值。
示例
#include <iostream> #include <cmath> int main() { std::cout << "tanh(1) = " << std::tanh(1) << '\n' << "tanh(-1) = " << std::tanh(-1) << '\n' << "tanh(0.1)*sinh(0.2)-cosh(0.2) = " << std::tanh(0.1) * std::sinh(0.2) - std::cosh(0.2) << '\n'; // 特殊值 std::cout << "tanh(+0) = " << std::tanh(+0.0) << '\n' << "tanh(-0) = " << std::tanh(-0.0) << '\n'; }
输出:
tanh(1) = 0.761594 tanh(-1) = -0.761594 tanh(0.1)*sinh(0.2)-cosh(0.2) = -1 tanh(+0) = 0 tanh(-0) = -0