C Math asin() Function

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
<math.h>

What You’ll Learn

The asin() function computes the arc sine (inverse sine) of a number. Given a sine value between −1 and 1, it returns the angle in radians whose sine equals that value—the mirror image of acos() for opposite-over-hypotenuse ratios.

01

Inverse sin

Angle from ratio.

02

math.h

Link with -lm.

03

Domain

[−1, 1].

04

Range

[−π/2, π/2].

05

Radians

Not degrees.

06

NaN

|x| > 1.

Definition and Usage

asin (arc sine) answers: “What angle has this sine?” If sin(θ) = x and x is between −1 and 1, then asin(x) = θ (in radians, principal value).

On a right triangle, sine is opposite ÷ hypotenuse. If you know those two side lengths, their ratio is a valid input to asin(), and the result is the angle at the vertex between the hypotenuse and the adjacent side.

💡
Beginner Tip

acos uses adjacent ÷ hypotenuse; asin uses opposite ÷ hypotenuse. Pick the function that matches the sides you know.

📝 Syntax

Standard C declaration:

C
double asin(double x);

Related variants

C
float asinf(float x);           /* <math.h> */
long double asinl(long double x); /* <math.h> */

Parameters

  • x — sine value; must be in the range [−1, 1].

Return Value

  • Angle in radians in the range [−π/2, π/2].
  • asin(0) returns 0; asin(1) returns π/2; asin(−1) returns −π/2.
  • If |x| > 1, returns NaN and may set errno to EDOM.

Headers and linking

  • #include <math.h>
  • Compile: gcc asin.c -std=c11 -o asin -lm

⚡ Quick Reference

CallMeaningResult (approx.)
asin(0)sin(0°) = 00 radians
asin(0.5)sin(30°) = 0.50.5236 (π/6)
asin(1)sin(90°) = 11.5708 (π/2)
asin(-1)sin(−90°) = −1-1.5708 (−π/2)
asin(x) * 180 / M_PIConvert to degreesAngle in °
Inverse
asin(x)

Angle from sin

Forward
sin(angle)

Sin from angle

To degrees
rad * 180 / M_PI

Convert

Triangle
asin(opp/hyp)

Geometry

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. The -lm flag links the math library on Linux and macOS.

📚 Getting Started

Compute arc sine and print the result in radians.

Example 1 — Basic Arc Sine

Find the angle whose sine is 0.5 (30° in radians).

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = 0.5;
    double result = asin(x);

    printf("The arc sine of %.1f is: %.6f radians\n", x, result);

    return 0;
}

How It Works

asin(0.5) returns π/6 radians because sin(π/6) = 0.5. This matches the reference example with cleaner formatting.

Example 2 — Endpoints of the Domain

asin(1) is π/2; asin(−1) is −π/2.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("asin(-1) = %.6f radians\n", asin(-1.0));
    printf("asin( 0) = %.6f radians\n", asin(0.0));
    printf("asin( 1) = %.6f radians\n", asin(1.0));

    return 0;
}

How It Works

Unlike acos(), asin() can return negative angles. The output range is symmetric: [−π/2, π/2].

📈 Practical Patterns

Degrees conversion, triangle geometry, and inverse verification.

Example 3 — Convert Radians to Degrees

Display the same angle in both units.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    double x = 0.5;
    double rad = asin(x);
    double deg = rad * 180.0 / M_PI;

    printf("asin(%.1f) = %.4f rad = %.1f degrees\n", x, rad, deg);

    return 0;
}

How It Works

Multiply radians by 180/π to get degrees. No special rad2deg function exists in standard C—this one-line conversion is the portable approach.

Example 4 — Angle in a Right Triangle

Opposite = 3, hypotenuse = 5 → sin(θ) = 3/5.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    double opposite = 3.0;
    double hypotenuse = 5.0;
    double sine_ratio = opposite / hypotenuse;
    double angle_deg = asin(sine_ratio) * 180.0 / M_PI;

    printf("sin(theta) = %.0f / %.0f = %.2f\n",
           opposite, hypotenuse, sine_ratio);
    printf("theta = %.1f degrees\n", angle_deg);

    return 0;
}

How It Works

In a 3-4-5 triangle, the angle opposite the side of length 3 satisfies sin(θ) = 3/5. asin(0.6) recovers that angle—about 36.9°.

Example 5 — Verify asin() with sin()

Inverse and forward sine undo each other on valid inputs.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double values[] = { -1.0, -0.5, 0.0, 0.5, 1.0 };
    size_t i;

    for (i = 0; i < sizeof values / sizeof values[0]; i++) {
        double x = values[i];
        double angle = asin(x);
        double back = sin(angle);

        printf("x=%5.1f  asin(x)=%.4f  sin(asin(x))=%.6f\n",
               x, angle, back);
    }

    return 0;
}

How It Works

sin(asin(x)) should equal x when x is in [−1, 1]. Small floating-point differences may appear beyond six decimal places.

🚀 Common Use Cases

  • Geometry — find an angle from opposite and hypotenuse side lengths.
  • 2D graphics — compute elevation or pitch angles from normalized vectors.
  • Game development — aim angles and projectile trajectories from sine components.
  • Signal processing — recover phase angles from sine values.
  • Pair with sin() — use sin forward and asin to reverse it.

🧠 How asin() Works

1

Validate input

Check that x is in [−1, 1]; otherwise return NaN.

Domain
2

Invert sine

Find θ such that sin(θ) = x using the math library.

Compute
3

Pick principal value

Return the angle in [−π/2, π/2] radians.

Range
=

Angle in radians

Ready for sin(), rotation code, or degree conversion.

📝 Notes

  • Input must be in [−1, 1]; values outside that range produce NaN.
  • Output is in [−π/2, π/2] radians—can be negative unlike acos().
  • Link with -lm when using GCC/Clang on Unix-like systems.
  • Use asinf or asinl for float or long double data.
  • For quadrant-aware angles from (x, y), prefer atan2(y, x) over asin.

⚡ Optimization

asin() is implemented in the platform math library and is already optimized. Cache results when the same ratio is computed repeatedly. For 2D direction vectors, atan2 often avoids separate quadrant logic that a naive asin(y/hyp) approach might need.

Conclusion

asin() turns a sine value into an angle in radians. Keep the input between −1 and 1, remember to link -lm, and convert to degrees when your users expect them.

Next up: asinh() for inverse hyperbolic sine, or explore sin() for the forward circular sine.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Keep x in [−1, 1] before calling
  • Convert radians to degrees for user-facing output
  • Use asinf for float pipelines
  • Pick asin when you have opposite/hypotenuse

❌ Don’t

  • Pass angles in degrees to asin()
  • Assume output is always non-negative (unlike acos)
  • Forget -lm on Linux builds
  • Ignore NaN when input comes from user data
  • Use asin when atan2 fits better

Key Takeaways

Knowledge Unlocked

Five things to remember about asin()

Inverse sine in C, explained simply.

5
Core concepts
📚 02

math.h

Link -lm.

Setup
🔢 03

[−1, 1]

Valid input.

Domain
🎯 04

[−π/2, π/2]

Output range.

Range
💰 05

Radians

Not degrees.

Units

❓ Frequently Asked Questions

asin() returns the arc sine (inverse sine) of x—the angle in radians whose sine equals x. For example, asin(0.5) is about 0.524 radians (30 degrees) because sin(30°) = 0.5.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double asin(double x).
x must be in the range [-1, 1]. That matches any valid sine ratio (opposite ÷ hypotenuse on a right triangle). If |x| > 1, asin() returns NaN.
Radians. Multiply by 180.0 / M_PI to convert to degrees. Define _USE_MATH_DEFINES before math.h on MSVC for M_PI.
The result is always between -pi/2 and pi/2 radians (about -1.5708 to 1.5708). asin(1) is pi/2; asin(-1) is -pi/2; asin(0) is 0.
sin() takes an angle in radians and returns its sine. asin() does the reverse: it takes a sine value and returns the angle. They are inverse operations on [-1, 1].
Did you know?

Because sine is not one-to-one over all angles, asin() returns only the principal value between −π/2 and π/2. That is why asin(0.5) gives π/6 (30°) and not 150° or other angles that also have sine 0.5.

Explore C Math Functions

Continue with asinh() or browse the full math function reference.

Math Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

4 people found this page helpful