Namespaces
Variants

atan, atanf, atanl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
定义于头文件 <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 )。若参数为复数,则宏调用对应的复数函数( catanf catan catanl )。

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

(since C23)

目录

参数

arg - 浮点数值

返回值

If no errors occur, the arc tangent of arg ( arctan(arg) ) in the range [-
π
2
; +
π
2
]
radians, is returned.

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

错误处理

错误报告方式遵循 math_errhandling 中的规范。

如果实现支持 IEEE 浮点算术 (IEC 60559):

  • 若参数为 ±0,则不作修改直接返回;
  • 若参数为 +∞,则返回 +π/2;
  • 若参数为 -∞,则返回 -π/2;
  • 若参数为 NaN,则返回 NaN。

注释

POSIX 规范 规定,在下溢情况下,将原样返回 arg ,若不支持此行为,则返回不大于 DBL_MIN FLT_MIN LDBL_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 atan 函数 (p: TBD)
  • 7.25 类型通用数学 <tgmath.h> (p: TBD)
  • F.10.1.3 atan 函数 (p: TBD)
  • C17 标准 (ISO/IEC 9899:2018):
  • 7.12.4.3 atan 函数 (p: 174)
  • 7.25 泛型数学 <tgmath.h> (p: 272-273)
  • F.10.1.3 atan 函数 (p: 378)
  • C11 标准 (ISO/IEC 9899:2011):
  • 7.12.4.3 atan 函数 (p: 238-239)
  • 7.25 类型泛型数学 <tgmath.h> (p: 373-375)
  • F.10.1.3 atan 函数 (p: 519)
  • C99标准(ISO/IEC 9899:1999):
  • 7.12.4.3 atan函数 (p: 219)
  • 7.22 泛型数学 <tgmath.h> (p: 335-337)
  • F.9.1.3 atan函数 (p: 456)
  • C89/C90 标准 (ISO/IEC 9899:1990):
  • 4.5.2.3 atan 函数

参阅

使用符号确定象限计算反正切
(函数)
(C99) (C99)
计算反正弦 ( arcsin(x) )
(函数)
(C99) (C99)
计算反余弦 ( arccos(x) )
(函数)
(C99) (C99)
计算正切 ( tan(x) )
(函数)
(C99) (C99) (C99)
计算复数反正切
(函数)
C++ 文档 for atan