Related Tags

d
communitycreator

# What is acos() in D?

harris910

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

The image below shows the mathematical representation of the acos() function.

Mathematical representation of the inverse cosine function

Note: std.math is required for this function.

To convert radians to degrees, use the following formula:

degrees = radians * ( 180.0 / PI )


### Syntax

acos(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 acos() returns -NaN.

### Return value

acos() returns the inverse cosine of a number (in radians) that is sent as a parameter. The return value lies in the interval [0, pi] radians.

### Code

The following code shows how to use the acos() function in D.

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

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

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

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

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

return 0;
}
Using acos() in a program

RELATED TAGS

d
communitycreator

CONTRIBUTOR

harris910
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time 