C++11标准模板(STL)- 常用数学函数 - 计算双曲正弦 (sh(x))(std::sinh, std::sinhf, std::sinhl)

常用数学函数

计算双曲正弦 (sh(x))

std::sinh, 
std::sinhf, 
std::sinhl

定义于头文件 <math.h>

float       sinhf( float arg );

(1)(C99 起)

double      sinh( double arg );

(2)

long double sinhl( long double arg );

(3)(C99 起)

定义于头文件 <tgmath.h>

#define sinh( arg )

(4)(C99 起)

1-3) 计算 arg 的双曲正弦。

4) 泛型宏:若参数拥有 long double 类型,则调用 sinhl 。否则,若参数拥有整数类型或 double 类型,则调用 sinh 。否则调用 sinhf 。若参数为复数,则宏调用对应的复数函数( csinhf 、 csinh 、 csinhl )。

参数

arg-表示双曲角的浮点值

返回值

若不出现错误,则返回 arg 的双曲正弦( sinh(arg) 或

earg
-e-arg
2

)。

若出现上溢所致的值域错误,则返回 ±HUGE_VAL±HUGE_VALF±HUGE_VALL

若出现下溢所致的值域错误,则返回(舍入后的)正确结果。

错误处理

报告 math_errhandling 中指定的错误。

若实现支持 IEEE 浮点算术( IEC 60559 ),则

  • 若参数为 ±0 或 ±∞ ,则返回不修改的参数
  • 若参数为 NaN ,则返回 NaN

注意

POSIX 指定在下溢情况下,返回不修改的 arg ,而若不支持如此,则返回不大于 DBL_MIN 、 FLT_MIN 和 LDBL_MIN 的实现定义值。

调用示例

#include <iostream>
#include <cstdlib>
#include <typeinfo>
#include <cinttypes>
#include <cmath>
#include <math.h>
#include <tgmath.h>

int main()
{
    //1-3) 计算 arg (以弧度度量)的正弦。
    const float fNumber = std::acos(-1);
    std::cout << "typeid(float).name():   " << typeid(float).name() << std::endl;
    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << fNumber / i << "):   "
                  << std::sinh(fNumber / i) << std::endl;
    }
    std::cout << std::endl;

    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << - fNumber / i << "):   "
                  << std::sinh(- fNumber / i) << std::endl;
    }
    std::cout << std::endl;

    const double dNumber = std::acos(-1);
    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << dNumber / i << "):   "
                  << std::sinh(dNumber / i) << std::endl;
    }
    std::cout << std::endl;

    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << - dNumber / i << "):   "
                  << std::sinh(- dNumber / i) << std::endl;
    }
    std::cout << std::endl;

    const long double ldNumber = std::acos(-1);
    std::cout << "typeid(long double).name():   " << typeid(long double).name() << std::endl;
    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << ldNumber / i << "):   "
                  << std::sinh(ldNumber / i) << std::endl;
    }
    std::cout << std::endl;

    for (int i = 1; i <= 10; i += 1)
    {
        std::cout << "std::sinh(" << - ldNumber / i << "):   "
                  << std::sinh(- ldNumber / i) << std::endl;
    }
    std::cout << std::endl;

    return 0;
}

输出

typeid(float).name():   f
std::sinh(3.14159):   11.5487
std::sinh(1.5708):   2.3013
std::sinh(1.0472):   1.24937
std::sinh(0.785398):   0.868671
std::sinh(0.628319):   0.670484
std::sinh(0.523599):   0.547853
std::sinh(0.448799):   0.464018
std::sinh(0.392699):   0.40287
std::sinh(0.349066):   0.356198
std::sinh(0.314159):   0.319353

std::sinh(-3.14159):   -11.5487
std::sinh(-1.5708):   -2.3013
std::sinh(-1.0472):   -1.24937
std::sinh(-0.785398):   -0.868671
std::sinh(-0.628319):   -0.670484
std::sinh(-0.523599):   -0.547853
std::sinh(-0.448799):   -0.464018
std::sinh(-0.392699):   -0.40287
std::sinh(-0.349066):   -0.356198
std::sinh(-0.314159):   -0.319353

std::sinh(3.14159):   11.5487
std::sinh(1.5708):   2.3013
std::sinh(1.0472):   1.24937
std::sinh(0.785398):   0.868671
std::sinh(0.628319):   0.670484
std::sinh(0.523599):   0.547853
std::sinh(0.448799):   0.464018
std::sinh(0.392699):   0.40287
std::sinh(0.349066):   0.356198
std::sinh(0.314159):   0.319353

std::sinh(-3.14159):   -11.5487
std::sinh(-1.5708):   -2.3013
std::sinh(-1.0472):   -1.24937
std::sinh(-0.785398):   -0.868671
std::sinh(-0.628319):   -0.670484
std::sinh(-0.523599):   -0.547853
std::sinh(-0.448799):   -0.464018
std::sinh(-0.392699):   -0.40287
std::sinh(-0.349066):   -0.356198
std::sinh(-0.314159):   -0.319353

typeid(long double).name():   e
std::sinh(3.14159):   11.5487
std::sinh(1.5708):   2.3013
std::sinh(1.0472):   1.24937
std::sinh(0.785398):   0.868671
std::sinh(0.628319):   0.670484
std::sinh(0.523599):   0.547853
std::sinh(0.448799):   0.464018
std::sinh(0.392699):   0.40287
std::sinh(0.349066):   0.356198
std::sinh(0.314159):   0.319353

std::sinh(-3.14159):   -11.5487
std::sinh(-1.5708):   -2.3013
std::sinh(-1.0472):   -1.24937
std::sinh(-0.785398):   -0.868671
std::sinh(-0.628319):   -0.670484
std::sinh(-0.523599):   -0.547853
std::sinh(-0.448799):   -0.464018
std::sinh(-0.392699):   -0.40287
std::sinh(-0.349066):   -0.356198
std::sinh(-0.314159):   -0.319353

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值