Related Tags

d
communitycreator

# What is asin() in D?

harris910

The asin() function, also called the arc sine function, returns the inverse sine of a number. To be more specific, it returns the inverse sine of a number in radians.

The figure below shows the mathematical representation of the asin() function.

Mathematical representation of the inverse sine function

Note: std.math is required for this function.

To convert radians to degrees, use the following formula:

degrees = radians * ( 180.0 / PI )


### Syntax

asin(number)
//number can be real, float, or double.


### Parameters

This function requires a number as a parameter. The parameter must be a value between -1 and 1.

• -1 <= parameter <= 1.

• If the value is outside -1 <= parameter <= 1, then asin() returns -NaN.

### Return value

asin() returns the inverse sine of the number that is sent as a parameter in radians. The return value lies in the interval [-PI/2, PI/2] radians.

### Code

The code below demonstrates how to use the asin() function in D.

import core.stdc.stdio;
import std.stdio;
import std.math;

int main() {
writeln("The value of asin(0.5): ",asin(0.5) ," Radians");

writeln("The value of asin(-0.5): ",asin(-0.5) ," Radians");

//applying asin() and then converting the result in radians to degrees
// PI = 3.14159265
double result=asin(0.5) * (180.0 / PI);
writeln("The value of asin(0.5): ",result," Degrees");

//error output
writeln("The value of asin(1.5): ",asin(1.5));
writeln("The value of asin(-1.5): ",asin(-1.5));

return 0;
}

### Explanation

• In lines 8 and 11, we use the asin() function to convert 0.5 to radians.
• In line 17, we use the asin() function to convert result into degree.
• In lines 20 and 21, we use the asin() function to show error nan.

RELATED TAGS

d
communitycreator

CONTRIBUTOR

harris910
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time