C++ Program to find the arcsine of the given value


In trigonometry, there are a few ratios that we use the most, sine, cosine, tangent, and some others. From a given angle, these ratios can be calculated. However, if we have the ratio values, we can also calculate the angle using inverse trigonometric functions.

In this article, we shall discuss how to get the angle in radian from the sine value through the inverse-sine (arcsine) method in C++.

The asin() function

The asin() method is used to compute the angle using the inverse trigonometric sine function. This function is present inside the standard library in C++. We need to import the cmath library to use this method. This function takes returns angle in radians by taking sine value as input. The following uses the simple syntax −

Syntax

#include < cmath >
asin( <sine value> )

The sine value must be in the range [-1 to +1] (both included). Otherwise, a domain error will be raised, and it will return Not-A-Number (nan). The returned value will be in the range $\mathrm{[-\:\frac{\pi}{2},\frac{\pi}{2}]}$(both included)

Algorithm

  • Take sine value x as input
  • Use asin( x ) to calculate the sin−1(x)
  • Return result.

Example

#include <iostream> #include <cmath> using namespace std; float solve( float x ) { float answer; answer = asin( x ); return answer; } int main() { float angle, ang_deg; angle = solve( 0.7071067 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given sine value 0.7071067 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 0.866025 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given sine value 0.866025 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 1 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given sine value 1 is: " <<; angle << " = " << ang_deg << " (in degrees)" << endl; angle = solve( 0.5 ); ang_deg = angle * 180 / 3.14159; cout << "The angle (in radian) for given sine value 0.5 is: " << angle << " = " << ang_deg << " (in degrees)" << endl; }

Output

The angle (in radian) for given sine value 0.7071067 is: 0.785398 = 45 (in degrees)
The angle (in radian) for given sine value 0.866025 is: 1.0472 = 60 (in degrees)The angle (in radian) for given sine value 1 is: 1.5708 = 90.0001 (in degrees)
The angle (in radian) for given sine value 0.5 is: 0.523599 = 30 (in degrees)

Here the asin() function takes the sine value and returns the angle in radian format. Here we have converted the output from radian to degrees using the following formula

$$\mathrm{\theta_{deg}\:=\:\theta_{rad}\:\times\:\frac{180}{\pi}}$$

Conclusion

To perform the inverse trigonometric operation from the sine value we use the asin() function from the cmath library. This function takes the sine value as input and returns the given angle in the radian unit. In older versions of C / C++, the return type was double, but later versions in C++ used the overloaded form for float and long-double additionally. While an integer value is passed as an argument, it will cast the input parameter into double and call the asin() method corresponding to the double-type parameter.

Updated on: 19-Oct-2022

332 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements