Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C library function - asin()

C library function - asin()

C Standard Library - <math.h> C Standard Library -

Description

asin() is a function in the C standard library is a function used to compute the arcsine of a number (also known as the inverse sine function among inverse trigonometric functions). The function accepts a real number between -1 and 1 and returns the arcsine of the value, in radians.

Declaration

The following is the declaration of the asin() function:



#include 



double asin(double x);

float asinf(float x);

long double asinl(long double x);

Parameters

Return Value

Example

The following example demonstrates the use of the asin() function.

Example

#include

#include

int

main

(

)

{

   

double

x

=

0.5

;

   

double

result

=

asin

(

x

)

;

   

printf

(

"asin(%f) = %f radians\n"

,

x

,

result

)

;

   

printf

(

"asin(%f) = %f degrees\n"

,

x

,

result

180

/

M_PI

)

;

   

return

0

;

}

Code analysis:

Let's compile and run the above program, which will produce the following result:



asin(0.500000) = 0.523599 radians

asin(0.500000) = 30.000000 degrees

Error handling

If the input x is outside the valid range [-1, 1],asin() will return NaN and set errno is EDOM. You can use isnan() to check whether the result is NaN:

Example

#include

#include

#include

int

main

(

)

{

   

double

x

=

2.0

;

 

// Invalid input, outside the [-1, 1] range

    errno

=

0

;

 

// Reset errno

   

double

result

=

asin

(

x

)

;

   

if

(

errno

==

EDOM

)

{

       

printf

(

"Input value is out of domain. asin(%f) is not defined.\n"

,

x

)

;

   

}

else

{

       

printf

(

"asin(%f) = %f radians\n"

,

x

,

result

)

;

   

}

   

return

0

;

}

Code analysis:

Let's compile and run the above program, which will produce the following result:



asin(2.000000) = nan radians

asin() The function computes the arcsine of a given value and is a common tool for handling inverse trigonometric operations. When using it, ensure the input value is within [-1, 1] and handle possible error conditions. By converting the result to degrees, you can understand the result more intuitively.

C Standard Library - <math.h> C Standard Library -