Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#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);
Calculates the arcsine of x, in the range -pi/2 to pi/2 radians.
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.
⁄* 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 );
}
}
Enter x
0.2 is entered
asin( 0.200000 ) = 0.201358