Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

# What is acos() in Dart?

harris910

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

Figure 1 shows the mathematical representation of the acos() function:

Figure 1: Mathematical representation of inverse cosine function

Note: dart:math is required for this function.

To convert radians to degrees, use the following formula:

degrees = radians * ( 180.0 / pi )


### Syntax

double acos(double num)


### Parameter

• num: a numerical value of type double. The parameter must be a double value between -1 and 1.

If the value is outside the range-1 to 1 then, it returns NaN.

### Return value

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

### Code

import 'dart:convert';
import 'dart:math';
void main() {
//positive number in radians
print("The value of acos(0.5): ${acos(0.5)} Radians"); // negative number in radians print("The value of acos(-0.5):${acos(-0.5)} Radians");

//applying acos() and then converting the result in radians to degrees
// radians = 0.5
// PI = 3.14159265
double result=acos(0.5) * (180.0 / pi);
print("The value of acos(0.5): ${result} Degrees"); //error output print("The value of acos(1.5):${acos(1.5)} ");
print("The value of acos(-1.5): \${acos(-1.5)} ");
}

RELATED TAGS

dart
communitycreator

CONTRIBUTOR

harris910
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time