📜  C++ acos()(1)

📅  最后修改于: 2023-12-03 14:39:49.340000             🧑  作者: Mango

C++ acos()

The acos() function in C++ is used to calculate the arc cosine value of the given argument. The function returns the principal value of the arc cosine of the given argument, in the range from 0 to π, expressed in radians.

Syntax

The syntax of the acos() function is as follows:

#include <cmath>

double acos(double x);

Here, x is the argument whose arc cosine value is to be calculated. The function returns the arc cosine value of x.

Return Value

The acos() function returns the arc cosine value of the given argument, in the range from 0 to π, expressed in radians.

Examples

Here are few examples to demonstrate the usage of acos() function in C++.

#include <iostream>
#include <cmath>

int main() {
  double x = 0.5;
  double result = acos(x);
  std::cout << "The arc cosine value of " << x << " is: " << result << std::endl;
  
  x = -0.5;
  result = acos(x);
  std::cout << "The arc cosine value of " << x << " is: " << result << std::endl;
  
  return 0;
}

Output:

The arc cosine value of 0.5 is: 1.0472
The arc cosine value of -0.5 is: 2.0944
Notes
  • If the argument x is outside the range [-1, 1], the acos() function returns a NaN (not-a-number) value.
  • If the argument value is very close to -1 or 1, then the return value may not be accurate due to rounding errors in the calculation.
  • The acos() function returns values in radians. To convert the radians to degrees, multiply with the conversion factor (180/π).