What is Math acos() function in java?

In java, the arccosine or inverse of cosine can be calculated by using java.lang.Math.acos() method. This method from the Math library returns the inverse of cosine between 0 and pi. Furthermore, It takes the angle as an argument and returns arc cos.

Syntax

public static double acos(double number)

Parameters

number: the value whose inverse cosine will be computed.

Return value

The arc cos of argument value as a number. If the value NaN or infinity is passed in the argument. It’ll return NaN because the absolute value of NaN is greater than 1.

Explanation

In this example, we’ll be elaborating on acos() function which takes a double type value as an argument and returns the inverse of that number.

class AlgoIdeas {
    public static void main( String args[] ) {
		// passing positive infinity as an argument
        double ans = Math.acos(Double.POSITIVE_INFINITY);
        System.out.println("acos(∞) = " + ans);
		// passing NaN value as an arguemnt
        ans = Math.acos(Double.NaN);
        System.out.println("acos(NaN) = " + ans);
		// passing +1 as an arguemnt
        ans = Math.acos(1);
        System.out.println("acos(1) = " + ans);
		// passing 0 as an arguemnt
        ans = Math.acos(0);
        System.out.println("acos(0) = " +  ans);
		// passing 3/2 value as an arguemnt
        ans = Math.acos(3/2);
        System.out.println("acos(3/2) = " + ans);
		//passing -1 as an arguemnt
        ans = Math.acos(-1);
        System.out.println("acos(-1) = " + ans);
		// passing NaN value as an arguemnt
        ans = Math.acos(0.9);
        System.out.println("acos(0.9) = " + ans);
    }
}

Output

The above program will generate the following output when executed.

Stay in the Loop

Get the daily email from Algoideas that makes reading the news actually enjoyable. Join our mailing list to stay in the loop to stay informed, for free.

Latest stories

- Advertisement -

You might also like...