首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::tan

Defined in header <cmath>

?

?

float tan( float arg );

(1)

?

double tan( double arg );

(2)

?

long double tan( long double arg );

(3)

?

double tan( Integral arg );

(4)

(since C++11)

计算arg以弧度计算的百分比为28%,为29%。

4%29一组过载或接受任意参数的函数模板积分型等于2%29%28double29%。

参数

arg

-

value representing angle in radians, of a floating-point or Integral type

返回值

如果没有错误发生,则arg返回%28 tan%28 arg%29%29。

The result may have little or no significance if the magnitude of arg is large.

(until C++11)

如果发生域错误,则返回支持%29的实现定义值%28 NaN。

如果由于下流而发生范围错误,则返回舍入%29后的正确结果%28。

错误处理

如果实现支持ieee浮点算法%28IEC 60559%29,

  • 如果参数为±0,则返回
  • 如果参数为±∞,则返回NaNFE_INVALID提出来
  • 如果参数为nan,则返回nan。

注记

如果参数是无限的,则未指定为C%28中的域错误,C++将其提交给%29,但它被定义为POSIX中的域错误...

该函数在π%281/2+n%29处有数学极点,但是没有一个通用的浮点表示能够精确地表示π/2,因此没有出现极点误差的参数值。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cfenv>
 
#pragma STDC FENV_ACCESS ON
const double pi = std::acos(-1);
int main()
{
    // typical usage
    std::cout << "tan  (pi/4) = " << std::tan(  pi/4) << '\n' // 45 deg.
              << "tan(3*pi/4) = " << std::tan(3*pi/4) << '\n' // 135 deg
              << "tan(5*pi/4) = " << std::tan(5*pi/4) << '\n' // -135 deg
              << "tan(7*pi/4) = " << std::tan(7*pi/4) << '\n'; // -45 deg
    // special values
    std::cout << "tan(+0) = " << std::tan(0.0) << '\n'
              << "tan(-0) = " << std::tan(-0.0) << '\n';
    // error handling 
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "tan(INFINITY) = " << std::tan(INFINITY) << '\n';
    if(std::fetestexcept(FE_INVALID)) std::cout << "    FE_INVALID raised\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
tan  (pi/4) = 1
tan(3*pi/4) = -1
tan(5*pi/4) = 1
tan(7*pi/4) = -1
tan(+0) = 0
tan(-0) = -0
tan(INFINITY) = -nan
    FE_INVALID raised

二次

另见

sin

computes sine (sin(x)) (function)

cos

computes cosine (cos(x)) (function)

atan

computes arc tangent (arctan(x)) (function)

tan(std::complex)

computes tangent of a complex number (tan(z)) (function template)

tan(std::valarray)

applies the function std::tan to each element of valarray (function template)

c关于TAN的文件

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com