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

std::sin

Defined in header <cmath>

?

?

float sin( float arg );

(1)

?

double sin( double arg );

(2)

?

long double sin( long double arg );

(3)

?

double sin( 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 sin%28 arg%29%29-1;+1,被归还。

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中的域错误...

POSIX还规定,在发生底流的情况下,arg如果不支持,则实现定义的值不大于dbl。[医]敏·弗利特[医]和LDBL[医]民回来了。

二次

代码语言: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 << "sin(pi/6) = " << std::sin(pi/6) << '\n'
              << "sin(pi/2) = " << std::sin(pi/2) << '\n'
              << "sin(-3*pi/4) = " << std::sin(-3*pi/4) << '\n';
    // special values
    std::cout << "sin(+0) = " << std::sin(0.0) << '\n'
              << "sin(-0) = " << std::sin(-0.0) << '\n';
    // error handling 
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "sin(INFINITY) = " << std::sin(INFINITY) << '\n';
    if(std::fetestexcept(FE_INVALID)) std::cout << "    FE_INVALID raised\n";
}

二次

可能的产出:

二次

代码语言:javascript
复制
sin(pi/6) = 0.5
sin(pi/2) = 1
sin(-3*pi/4) = -0.707107
sin(+0) = 0
sin(-0) = -0
sin(INFINITY) = -nan
    FE_INVALID raised

二次

另见

cos

computes cosine (cos(x)) (function)

tan

computes tangent (tan(x)) (function)

asin

computes arc sine (arcsin(x)) (function)

sin(std::complex)

computes sine of a complex number (sin(z)) (function template)

sin(std::valarray)

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

C.罪恶文件

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com