C++ std::asin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cmath>

Definition

In C++, std::asin(x) is the inverse sine (also called arcsine). It undoes std::sin(): if the sine of an angle is 0.5, asin(0.5) gives back that angle, about 0.5236 radians, which is 30 degrees.

The input must be between -1 and 1, because no sine is ever outside that range. The answer is an angle in radians between -pi / 2 and pi / 2. Multiply by 180 / pi to get degrees.

std::asin() is declared in <cmath> and is part of the group Trigonometry. Trigonometric functions use radians, not degrees. To convert degrees, multiply by std::numbers::pi / 180 (C++20).

Syntax

Include <cmath> and call std::asin. Start with these lines.

C++
double a = std::asin(0.5);    // double version
float  b = std::asin(0.5f);   // float version
CallWhat it does
std::asin(0.5)Passes a double and returns a double. Here the result is 0.523599.
std::asin(0.5f)Passes a float, so the float overload runs and returns a float.
std::asin(1)An integer is converted to double. Returns 1.5708 (pi / 2).

Write std::asin so the C++ overloads for float, double, and long double are used.

Library declarations
C++
float       asin(float x);
double      asin(double x);
long double asin(long double x);
double      asin(Integer x);   // for integer types

Parameters

ParameterDescription
xRequired. A number from -1 to 1. Anything else is outside the domain. An integer is converted to double.

Return Value

Return ValueDescription
AngleThe angle in radians from -pi / 2 to pi / 2 whose sine is x.
NaNReturned when x is below -1 or above 1. This is a domain error.
0asin(0) is 0, and asin(-0.0) is -0.0.

C++ Examples

Example 1 — Inverse Sine of Common Values

Print asin() for a few numbers inside its range. The results are in radians.

C++
#include <cmath>
#include <iostream>

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

    for (double v : values) {
        std::cout << "asin(" << v << ") = " << std::asin(v) << '\n';
    }
    return 0;
}

How It Works

  1. Each number is a sine value, and asin() returns the angle that has this sine.
  2. asin(0.5) is 0.523599, which is pi / 6 or 30 degrees. asin(0) is 0.
  3. The ends of the range give the extremes: asin(1) is 1.5708 (pi / 2) and asin(-1) is -1.5708.

Example 2 — Convert the Result to Degrees

Radians are hard to read, so multiply by 180 / pi to see the angle in degrees.

C++
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numbers>

int main() {
    double ratios[] = {0.5, std::sqrt(3.0) / 2.0, 1.0};
    const double toDeg = 180.0 / std::numbers::pi;

    std::cout << std::fixed << std::setprecision(2);
    for (double r : ratios) {
        std::cout << "asin(" << r << ") = " << std::asin(r) * toDeg << " degrees\n";
    }
    return 0;
}

How It Works

  1. toDeg is 180 / pi, about 57.2958. Multiplying a radian value by it gives degrees.
  2. asin(0.5) gives 30.00 degrees. The second ratio, sqrt(3) / 2 or 0.87 when rounded, gives 60.00 degrees.
  3. A sine of 1 is the top of the wave, so the angle is 90.00 degrees. std::fixed prints two decimals for each line.

Example 3 — Outside the Range -1 to 1

Check what happens when the input is too big, and how to protect against a rounding error with std::min().

C++
#include <algorithm>
#include <cmath>
#include <iostream>

int main() {
    double tooBig = 1.5;
    double ratio = 1.0 + 2.2e-16;

    std::cout << "asin(1.5) is NaN: " << std::isnan(std::asin(tooBig)) << '\n';
    std::cout << "ratio > 1: " << (ratio > 1.0) << '\n';
    std::cout << "asin(ratio) is NaN: " << std::isnan(std::asin(ratio)) << '\n';
    std::cout << "clamped: " << std::asin(std::min(ratio, 1.0)) << '\n';
    return 0;
}

How It Works

  1. No angle has a sine of 1.5, so asin(1.5) is NaN and std::isnan() prints 1.
  2. ratio is only a tiny bit above 1 (1.0000000000000002), the kind of error a long calculation can leave behind. It is still outside the range, so NaN again.
  3. std::min(ratio, 1.0) cuts the value back to 1. Now asin() returns 1.5708. It is a good habit to clamp a computed ratio before asin().

Frequently Asked Questions

std::asin(x) returns the angle, in radians, whose sine is x. The input must be between -1 and 1, and the result is between -pi/2 and pi/2.
An angle in radians from -pi/2 to pi/2. If x is outside the range -1 to 1, the result is NaN.
From -1 to 1. Any other value returns NaN, because no angle has a sine outside that range.
No, radians. For degrees, multiply by 180 / std::numbers::pi. asin(0.5) is 0.523599 radians, or 30 degrees.
Include <cmath> and write std::asin(). That always works and picks the C++ overloads. The global name ::asin often works too, but the standard does not promise it, and it may only take a double.

Next: asinh()

Keep going through the <cmath> functions. Inverse hyperbolic sine of a number.

asinh() tutorial →

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.

10 people found this page helpful