std::asin

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)
(C++11)
(C++11)
Power functions
(C++11)
(C++11)
Trigonometric and hyperbolic functions
(C++11)
(C++11)
(C++11)
Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
Classification/Comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)(C++11)(C++11)(C++11)(C++11)
 
Defined in header <cmath>
float       asin( float arg );
(1)
double      asin( double arg );
(2)
long double asin( long double arg );
(3)
double      asin( Integral arg );
(4) (since C++11)

Computes the principal value of the arc sine of arg.

4) A set of overloads or a function template accepting an argument of any integral type. Equivalent to 2) (the argument is cast to double).

Contents

[edit] Parameters

arg - value of a floating-point or Integral type

[edit] Return value

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

If a domain error occurs, an implementation-defined value is returned (NaN where supported)

If a range error occurs due to underflow, the correct result (after rounding) is returned.

[edit] Error handling

Errors are reported as specified in math_errhandling

Domain error occurs if arg is outside the range [-1.0; 1.0]

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • If the argument is ±0, it is returned unmodified
  • If |arg| > 1, a domain error occurs and NaN is returned.
  • if the argument is NaN, NaN is returned

[edit] Example

#include <cmath>
#include <iostream>
#include <cerrno>
#include <cfenv>
#include <cstring>
 
#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';
    // special values
    std::cout << "asin(0.0) = " << asin(0) << " asin(-0.0)=" << asin(-0.0) << '\n';
    // error handling 
    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';
}

Possible output:

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

[edit] See also

computes arc cosine (arccos(x))
(function)
computes arc tangent (arctan(x))
(function)
arc tangent, using signs to determine quadrants
(function)
computes sine (sin(x))
(function)
computes arc sine of a complex number (arcsin(z))
(function template)
applies the function std::asin to each element of valarray
(function template)
C documentation for asin