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

std::atan2

Defined in header <cmath>

?

?

float atan2( float y, float x );

(1)

?

double atan2( double y, double x );

(2)

?

long double atan2( long double y, long double x );

(3)

?

Promoted atan2( Arithmetic1 y, Arithmetic2 x );

(4)

(since C++11)

的弧切线的计算y/x使用参数的符号来确定正确的象限。

4%29一组过载或函数模板,用于1-3%29未涵盖的算术类型的所有参数组合。如果有任何争论积分型,它被铸造成double.如果有任何争论long double,则返回类型Promoted也是long double,否则返回类型总是double...

参数

x, y

-

values of floating-point or integral types

返回值

如果没有错误发生,则将y/x28arctan%28

Y型

*。

X

29%%29在范围内-π;+π弧度,被归还。

Y论点

返回值

二次

二次

X参数

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

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

错误处理

错误按数学[医]错误处理...

域错误可能发生在xy都是零。

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

  • 如果xy都是零,域错误发生
  • 如果xy都为零,也不会发生距离错误。
  • 如果y为零,则不发生极差。
  • 如果y±0x是否定的或-0,,,±π返回
  • 如果y±0x是积极的或+0,,,±0返回
  • 如果y±∞x是有限的,±π/2返回
  • 如果y±∞x-∞,,,±3π/4返回
  • 如果y±∞x+∞,,,±π/4返回
  • 如果x±0y是阴性的,-π/2返回
  • 如果x±0y是积极的,+π/2返回
  • 如果x-∞y是有限的和正的,返回
  • 如果x-∞y是有限的和负的,返回
  • 如果x+∞y是有限的和正的,+0返回
  • 如果x+∞y是有限的和负的,-0返回
  • 如果x是南还是y是南,南回来了

注记

std::atan2(y, x)等于std::arg(std::complex<double>(x,y))...

POSIX指定如果是地下水流,y/x是返回的值,如果不支持,则实现定义的值不大于dbl。[医]敏·弗利特[医]和LDBL[医]民回来了。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
 
int main()
{
    // normal usage: the signs of the two arguments determine the quadrant
    std::cout << "(+1,+1) cartesian is (" << hypot(1,1)
              << ',' << atan2(1,1) << ") polar\n"  // atan2(1,1) = +pi/4, Quad I
              << "(+1,-1) cartesian is (" << hypot(1,-1)
              << ',' << atan2(1,-1) << ") polar\n" // atan2(1, -1) = +3pi/4, Quad II
              << "(-1,-1) cartesian is (" << hypot(-1,-1)
              << ',' << atan2(-1,-1) << ") polar\n" // atan2(-1,-1) = -3pi/4, Quad III
              << "(-1,+1) cartesian is (" << hypot(-1,1)
              << ',' << atan2(-1,1) << ") polar\n"; // atan2(-1,-1) = -pi/4, Quad IV
    // special values
    std::cout << "atan2(0, 0) = " << atan2(0,0)
              << " atan2(0,-0) = " << atan2(0,-0.0) << '\n'
              << "atan2(7, 0) = " << atan2(7,0)
              << " atan2(7,-0) = " << atan2(7,-0.0) << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
(+1,+1) cartesian is (1.41421,0.785398) polar
(+1,-1) cartesian is (1.41421,2.35619) polar
(-1,-1) cartesian is (1.41421,-2.35619) polar
(-1,+1) cartesian is (1.41421,-0.785398) polar
atan2(0, 0) = 0 atan2(0,-0) = 3.14159
atan2(7, 0) = 1.5708 atan2(7,-0) = 1.5708

二次

另见

asin

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

acos

computes arc cosine (arccos(x)) (function)

atan

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

arg

returns the phase angle (function template)

atan2(std::valarray)

applies the function std::atan2 to a valarray and a value (function template)

c关于atan的文件2

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com