Name

asin

Synopsis

Calculates the inverse sine of a number

#include <math.h>
doubleasin( double x );
float asinf( float x );        (C99)
long double asinl( long double x );        (C99)

asin() implements the inverse sine function, commonly called arc sine. The argument x must be between -1 and 1, inclusive: -1 ≤ x ≤ 1. If x is outside the function’s domain—that is, if x is greater than 1 or less than −1—the function incurs a domain error.

The return value is given in radians, and is thus in the range -π/2 ≤ asin(x) ≤ π/2.

Example

/*
 * Calculate the altitude of the sun (its angle upward from the horizon)
 * given the height of a vertical object and the length of the object's
 * shadow.
 */
#define PI 3.141593
#define DEG_PER_RAD (180.0/PI)

float height = 2.20F;
float length = 1.23F;
float altitude =asinf( height / sqrtf( height*height + length*length ));
printf( "The sun's altitude is %2.0f\xB0.\n", altitude * DEG_PER_RAD );

This code produces the following output:

The sun's altitude is 61°.

See Also

Arcsine functions for complex numbers: casin(), casinf(), and casinl()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.