atan, atanf, atanl

< c‎ | numeric‎ | math
在标头 <math.h> 定义
float       atanf( float arg );
(1) (C99 起)
double      atan( double arg );
(2)
long double atanl( long double arg );
(3) (C99 起)
_Decimal32  atand32( _Decimal32 arg );
(4) (C23 起)
_Decimal64  atand64( _Decimal64 arg );
(5) (C23 起)
_Decimal128 atand128( _Decimal128 arg );
(6) (C23 起)
在标头 <tgmath.h> 定义
#define atan( arg )
(7) (C99 起)
1-6) 计算 arg 的弧(反)正切主值。
7) 泛型宏:若实参拥有 long double 类型,则调用 (3) atanl。否则,若实参拥有整数类型或 double 类型,则调用 (2) atan。否则调用 (1) atanf。若实参为复数,则宏调用对应的复数函数(catanfcatancatanl)。

仅当实现预定义了 __STDC_IEC_60559_DFP__(即实现支持十进制浮点数)时,声明函数 (4-6)

(C23 起)

参数

arg - 浮点值

返回值

若不出现错误,则返回 arg[-
π
2
 ; +
π
2
] 弧度范围中的弧(反)正切(arctan(arg))。

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

错误处理

报告 math_errhandling 中指定的错误。

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

  • 若参数为 ±0,则返回不修改的参数
  • 若参数为 +∞,则返回 +π/2
  • 若参数为 -∞,则返回 -π/2
  • 若参数为 NaN,则返回 NaN

注意

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

示例

#include <math.h>
#include <stdio.h>
 
int main(void)
{
    printf("atan(1) = %f, 4*atan(1)=%f\n", atan(1), 4 * atan(1));
    // 特殊值
    printf("atan(Inf) = %f, 2*atan(Inf) = %f\n", atan(INFINITY), 2*atan(INFINITY));
    printf("atan(-0.0) = %+f, atan(+0.0) = %+f\n", atan(-0.0), atan(0));
}

输出:

atan(1) = 0.785398, 4*atan(1)=3.141593
atan(Inf) = 1.570796, 2*atan(Inf) = 3.141593
atan(-0.0) = -0.000000, atan(+0.0) = +0.000000

引用

  • C23 标准(ISO/IEC 9899:2024):
  • 7.12.4.3 The atan functions (第 TBD 页)
  • 7.25 Type-generic math <tgmath.h> (第 TBD 页)
  • F.10.1.3 The atan functions (第 TBD 页)
  • C17 标准(ISO/IEC 9899:2018):
  • 7.12.4.3 The atan functions (第 174 页)
  • 7.25 Type-generic math <tgmath.h> (第 272-273 页)
  • F.10.1.3 The atan functions (第 378 页)
  • C11 标准(ISO/IEC 9899:2011):
  • 7.12.4.3 The atan functions (第 238-239 页)
  • 7.25 Type-generic math <tgmath.h> (第 373-375 页)
  • F.10.1.3 The atan functions (第 519 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.12.4.3 The atan functions (第 219 页)
  • 7.22 Type-generic math <tgmath.h> (第 335-337 页)
  • F.9.1.3 The atan functions (第 456 页)
  • C89/C90 标准(ISO/IEC 9899:1990):
  • 4.5.2.3 The atan function

参阅

(C99)(C99)
计算反正切,以符号确定象限
(函数)
(C99)(C99)
计算反正弦(arcsin(x)
(函数)
(C99)(C99)
计算反余弦(arccos(x)
(函数)
(C99)(C99)
计算正切(tan(x)
(函数)
(C99)(C99)(C99)
计算复数反正切
(函数)