Namespaces
Variants

std:: asin, std:: asinf, std:: asinl

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
定义于头文件 <cmath>
(1)
float asin ( float num ) ;

double asin ( double num ) ;

long double asin ( long double num ) ;
(C++23 前)
/*floating-point-type*/
asin ( /*floating-point-type*/ num ) ;
(C++23 起)
(C++26 起为 constexpr)
float asinf ( float num ) ;
(2) (C++11 起)
(C++26 起为 constexpr)
long double asinl ( long double num ) ;
(3) (C++11 起)
(C++26 起为 constexpr)
SIMD 重载 (C++26 起)
定义于头文件 <simd>
template < /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/ < V >

asin ( const V & v_num ) ;
(S) (C++26 起)
附加重载 (C++11 起)
定义于头文件 <cmath>
template < class Integer >
double asin ( Integer num ) ;
(A) (C++26 起为 constexpr)
1-3) 计算 num 的反正弦主值。 库为所有 cv 未限定浮点类型提供了 std::asin 的重载,作为参数类型。 (since C++23)
S) SIMD 重载对 v_num 执行逐元素的 std::asin 运算。
(定义参见 math-floating-point deduced-simd-t
(since C++26)
A) 为所有整数类型提供了额外的重载,这些类型被视为 double
(since C++11)

目录

参数

num - 浮点数或整数值

返回值

If no errors occur, the arc sine of num ( arcsin(num) ) in the range [-
π
2
, +
π
2
]
, is returned.

如果发生定义域错误,则返回一个由实现定义的值(在支持 NaN 的情况下返回 NaN)。

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

错误处理

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

num 超出范围 [ - 1.0 , 1.0 ] 时会发生定义域错误。

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

  • 若参数为 ±0,则不作修改直接返回。
  • |num| > 1 ,则发生定义域错误并返回 NaN。
  • 若参数为 NaN,则返回 NaN。

注释

额外的重载不需要完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num std :: asin ( num ) std :: asin ( static_cast < double > ( num ) ) 具有相同效果即可。

示例

#include <cerrno>
#include <cfenv>
#include <cmath>
#include <cstring>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "asin(1.0) = " << asin(1) << '\n'
              << "2*asin(1.0) = " << 2 * asin(1) << '\n'
              << "asin(-0.5) = " << asin(-0.5) << '\n'
              << "6*asin(-0.5) =" << 6 * asin(-0.5) << '\n';
    // 特殊值
    std::cout << "asin(0.0) = " << asin(0) << " asin(-0.0)=" << asin(-0.0) << '\n';
    // 错误处理
    errno = 0;
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "asin(1.1) = " << asin(1.1) << '\n';
    if (errno == EDOM)
        std::cout << "    errno == EDOM: " << std::strerror(errno) << '\n';
    if (std::fetestexcept(FE_INVALID))
        std::cout << "    FE_INVALID raised" << '\n';
}

可能的输出:

asin(1.0) = 1.5708
2*asin(1.0) = 3.14159
asin(-0.5) = -0.523599
6*asin(-0.5) = -3.14159
asin(0.0) = 0 asin(-0.0)=-0
asin(1.1) = nan
    errno == EDOM: Numerical argument out of domain
    FE_INVALID raised

参阅

(C++11) (C++11)
计算反余弦( arccos(x)
(函数)
(C++11) (C++11)
计算反正切( arctan(x)
(函数)
(C++11) (C++11)
使用符号确定象限的反正切
(函数)
(C++11) (C++11)
计算正弦( sin(x)
(函数)
计算复数的反正弦( arcsin(z)
(函数模板)
将函数 std::asin 应用于 valarray 的每个元素
(函数模板)
C 文档 关于 asin