JavaScript Math.acos()

 In JavaScript, Math.acos() is a method of the Math object that returns the arccosine (inverse cosine) of a number.

 The result is expressed in radians, which is a measure of angle.

Syntax


Math.acos(x)
  • x: A number between -1 and 1 (inclusive). The function calculates the arccosine of this number.

Returns

  • The method returns a number between 0 and π radians (0 to π, inclusive), which is the angle whose cosine is x.

Key Points

  • Domain: The input value (x) must be between -1 and 1, inclusive. Values outside this range result in NaN (Not-a-Number).
  • Range: The output is between 0 and π radians.

Examples

Here are 10 examples demonstrating how Math.acos() works:

  1. Basic Arccosine


    console.log(Math.acos(1)); // 0 (cos(0) = 1)
  2. Arccosine of 0


    console.log(Math.acos(0)); // 1.5707963267948966 (π/2 radians)
  3. Arccosine of -1


    console.log(Math.acos(-1)); // 3.141592653589793 (π radians)
  4. Arccosine of 0.5


    console.log(Math.acos(0.5)); // 1.0471975511965979 (π/3 radians)
  5. Arccosine of -0.5


    console.log(Math.acos(-0.5)); // 2.0943951023931957 (2π/3 radians)
  6. Arccosine of 0.25


    console.log(Math.acos(0.25)); // 1.318116071652818
  7. Arccosine of -0.25


    console.log(Math.acos(-0.25)); // 1.8234765819369757
  8. Arccosine of a number slightly less than -1


    console.log(Math.acos(-1.00001)); // NaN (Out of domain)
  9. Arccosine of a number slightly more than 1


    console.log(Math.acos(1.00001)); // NaN (Out of domain)
  10. Arccosine of 0.9


    console.log(Math.acos(0.9)); // 0.45102681179626236

Usage Notes

  • The result of Math.acos() is in radians. To convert the result to degrees, you can use the formula:


    function radiansToDegrees(radians) { return radians * (180 / Math.PI); } let radians = Math.acos(0.5); console.log(radiansToDegrees(radians)); // 60 (degrees)
  • Ensure that the input to Math.acos() is within the valid range [-1, 1]. Values outside this range will return NaN.

Previous Post Next Post

Welcome, New Friend!

We're excited to have you here for the first time!

Enjoy your colorful journey with us!

Welcome Back!

Great to see you Again

If you like the content share to help someone

Thanks

Contact Form