asin(), asinf(), asinl() — Calculate arcsine

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double asin(double x);
float asin(float x);                  /* C++ only */
long double asin(long double x);      /* C++ only */
float asinf(float x);
long double asinl(long double x);

General description

Calculates the arcsine of x, in the range -pi/2 to pi/2 radians.

The value of x must be between -1 and 1.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

If x is less than -1 or greater than 1, the function sets errno to EDOM, and returns 0. Otherwise, it returns a nonzero value.

If the correct value would cause an underflow, 0 is returned and the value ERANGE is stored in errno.

Special behavior for IEEE: If successful, the function returns the arcsine of its argument x.

If x is less than -1 or greater than 1, the function sets errno to EDOM and returns NaNQ. No other errors will occur.

Example

CELEBA07
⁄* CELEBA07                                      

   This example prompts for a value for x.                                      
   It prints an error message if x is greater than 1 or                         
   less than -1; otherwise, it assigns the arcsine of                           
   x to y.                                                                      
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <stdlib.h>                                                             
#include <math.h>                                                               
#define MAX  1.0                                                                
#define MIN -1.0                                                                
                                                                                
int main(void)                                                                  
{                                                                               
  double x, y;                                                                  
                                                                                
  printf( "Enter x\n" );                                                        
  scanf( "%lf", &x );                                                           
                                                                                
  ⁄* Output error if not in range *⁄                                            
  if ( x > MAX )                                                                
    printf( "Error: %f too large for asin\n", x );                              
  else if ( x < MIN )                                                           
    printf( "Error: %f too small for asin\n", x );                              
  else {                                                                        
    y = asin( x );                                                              
    printf( "asin( %f ) = %f\n", x, y );                                        
  }                                                                             
}                                                                               
Output
Enter x
 0.2 is entered
asin( 0.200000 ) = 0.201358

Related information