Namespaces
Variants
Views
Actions

asin

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       asinf( float arg );
(since C99)
double      asin( double arg );
long double asinl( long double arg );
(since C99)

Computes arc sine of arg

Contents

[edit] Parameters

arg - floating point value

[edit] Return value

Arc sine of arg in radians in the range of [-π/2; π/2] radians.

Domain error occurs if arg is outside the range [-1.0; 1.0]. NaN is returned in that case and FE_INVALID is raised.

asin(+0) returns +0. asin(-0) returns -0.

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
#define PI acos(-1)
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    printf("asin(-1.0) = %+f\n",   asin(-1.0));   /* -pi/2 */
    printf("asin(+1.0) = %+f\n",   asin(+1.0));   /* +pi/2 */
    printf("asin(+0.0) = %+.1f\n", asin(+0.0));
    printf("asin(-0.0) = %+.1f\n", asin(-0.0));
    printf("asin(NAN)  = %.1f\n",  asin(NAN));
    printf("\n");
 
    /* domain error                       */
    /* "invalid" floating-point exception */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("asin(1.1)  = %f\n", asin(1.1));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
 
    return 0;
}

Possible output:

asin(-1.0) = -1.570796
asin(+1.0) = +1.570796
asin(+0.0) = +0.0
asin(-0.0) = -0.0
asin(NAN)  = nan
 
asin(1.1)  = nan
Numerical argument out of domain
current exceptions raised:  FE_INVALID

[edit] See also

computes arc cosine (arccos(x))
(function) [edit]
computes arc tangent (arctan(x))
(function) [edit]
arc tangent, using signs to determine quadrants
(function) [edit]
computes sine (sin(x))
(function) [edit]