asin() — Calculate Arcsine
Format
#include <math.h>
double asin(double x);
Language Level
ANSI
Threadsafe
Yes
Description
The asin()
function
calculates the arcsine of x, in the range
-π/2 to π/2 radians.
Return Value
The asin()
function
returns the arcsine of x. The value of x must
be between -1 and 1. If x is less than -1
or greater than 1, the asin()
function
sets errno to EDOM, and returns a value of 0.
Example
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: %lf too large for asin\n", x );
else if ( x < MIN )
printf( "Error: %lf too small for asin\n", x );
else
{
y = asin( x );
printf( "asin( %lf ) = %lf\n", x, y );
}
}
/**************** Output should be similar to ******************
Enter x
asin( 0.200000 ) = 0.201358
*/