php atan2,atan2f - [ C语言中文开发手册 ] - 在线原生手册 - php中文网

在头文件中定义float       atan2f( float y, float x );(1)(since C99)

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

long double atan2l( long double y, long double x );(3)(since C99)

Defined in header

#define atan2( arg )(4)(since C99)

1-3)y/x使用参数符号计算反正切以确定正确的象限。

4)类型 - 通用宏:如果参数具有类型long double,atan2l则被调用。否则,如果参数具有整数类型或类型double,atan2则调用该参数。否则,atan2f被调用。

参数

x,y-浮点值

返回值

如果没有错误发生,则y/x(arctan(

| y |

|:----|

| x |

))在-π范围内; +π弧度,返回。

Y参数

返回值

X参数

如果发生域错误,则返回实现定义的值。

如果由于下溢而发生范围错误,则返回正确的结果(舍入后)。

错误处理

按照math_errhandling中的指定报告错误。

如果x和y都为零,则可能会出现域错误。

如果实现支持IEEE浮点运算(IEC 60559),

如果x和y都为零,则不会发生域错误

如果x和y都是零,则范围错误也不会发生

如果y为零,则不会发生极点错误

如果y是±0和x为负或-0,±π返回

如果y是±0并且x是肯定的+0,±0则返回

如果y是±∞并且x是有限的,±π/2则返回

如果y是±∞和x是-∞,±3π/4返回

如果y是±∞和x是+∞,±π/4返回

如果x是±0且y为负数,-π/2则返回

如果x是±0且y为正,+π/2则返回

如果x是-∞并且y是有限且肯定的,+π则返回

如果x是-∞并且y是有限且负面的,-π则返回

如果x是+∞并且y是有限且肯定的,+0则返回

如果x是+∞并且y是有限且负面的,-0则返回

如果x是NaN或yNaN,则返回NaN

笔记

atan2(y, x)相当于carg(x + I*y)。

POSIX指定在发生下溢时y/x返回值,如果不支持,则返回不大于DBL_MIN,FLT_MIN和LDBL_MIN的实现定义值。

#include #include 

int main(void){    // normal usage: the signs of the two arguments determine the quadrant    // atan2(1,1) = +pi/4, Quad I    printf("(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1), atan2( 1, 1));    // atan2(1, -1) = +3pi/4, Quad II    printf("(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1,-1), atan2( 1,-1));    // atan2(-1,-1) = -3pi/4, Quad III    printf("(-1,-1) cartesian is (%f,%f) polar\n", hypot(-1,-1), atan2(-1,-1));    // atan2(-1,-1) = -pi/4, Quad IV    printf("(-1,+1) cartesian is (%f,%f) polar\n", hypot(-1, 1), atan2(-1, 1));

// special values    printf("atan2(0, 0) = %f atan2(0, -0)=%f\n", atan2(0,0), atan2(0,-0.0));    printf("atan2(7, 0) = %f atan2(7, -0)=%f\n", atan2(7,0), atan2(7,-0.0));}

输出:

(+1,+1) cartesian is (1.414214,0.785398) polar(+1,-1) cartesian is (1.414214,2.356194) polar(-1,-1) cartesian is (1.414214,-2.356194) polar(-1,+1) cartesian is (1.414214,-0.785398) polaratan2(0, 0) = 0.000000 atan2(0, -0)=3.141593atan2(7, 0) = 1.570796 atan2(7, -0)=1.570796

参考

C11标准(ISO / IEC 9899:2011):7.12.4.4 atan2函数(p:239)

7.25类型通用数学(p:373-375)

F.10.1.4 atan2函数(p:519)

C99标准(ISO / IEC 9899:1999):7.12.4.4 atan2函数(p:219)

7.22类型通用数学(p:335-337)

F.9.1.4 atan2函数(p:456)

C89 / C90标准(ISO / IEC 9899:1990):4.5.2.4 atan2函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值