Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Get the angle whose sine is float value argument in C#
To get the angle whose sine is a float value argument in C#, we use the MathF.Asin() method. This method returns the arcsine (inverse sine) of the specified number in radians. The input value must be between -1 and 1, otherwise the method returns NaN (Not a Number).
Syntax
Following is the syntax for MathF.Asin() method −
public static float Asin(float x)
Parameters
x − A number representing a sine value. Must be between -1 and 1 inclusive.
Return Value
Returns the arcsine of the specified number in radians. If the input is outside the range [-1, 1], it returns NaN.
Using MathF.Asin() with Valid Input
Example
using System;
public class Demo {
public static void Main() {
float val1 = 0.1f;
float val2 = 0.5f;
float val3 = 1.0f;
Console.WriteLine("Angle (val1) = " + (MathF.Asin(val1)));
Console.WriteLine("Angle (val2) = " + (MathF.Asin(val2)));
Console.WriteLine("Angle (val3) = " + (MathF.Asin(val3)));
}
}
The output of the above code is −
Angle (val1) = 0.1001674 Angle (val2) = 0.5235988 Angle (val3) = 1.570796
Using MathF.Asin() with Invalid Input
Example
using System;
public class Demo {
public static void Main() {
float val1 = 1.2f;
float val2 = 45.5f;
float val3 = -2.0f;
Console.WriteLine("Angle (val1) = " + (MathF.Asin(val1)));
Console.WriteLine("Angle (val2) = " + (MathF.Asin(val2)));
Console.WriteLine("Angle (val3) = " + (MathF.Asin(val3)));
}
}
The output of the above code is −
Angle (val1) = NaN Angle (val2) = NaN Angle (val3) = NaN
Converting Radians to Degrees
Since MathF.Asin() returns the result in radians, you may need to convert it to degrees for better understanding −
Example
using System;
public class Demo {
public static void Main() {
float sineValue = 0.5f;
float angleRadians = MathF.Asin(sineValue);
float angleDegrees = angleRadians * (180.0f / MathF.PI);
Console.WriteLine("Sine value: " + sineValue);
Console.WriteLine("Angle in radians: " + angleRadians);
Console.WriteLine("Angle in degrees: " + angleDegrees);
}
}
The output of the above code is −
Sine value: 0.5 Angle in radians: 0.5235988 Angle in degrees: 30.00001
Conclusion
The MathF.Asin() method calculates the arcsine of a float value and returns the angle in radians. The input must be between -1 and 1; values outside this range return NaN. Convert the result to degrees by multiplying by 180/? if needed.
