ADVERTISEMENT
ADVERTISEMENT

Golang math.Acos() Function with Examples

Golang | math.Acos() Function: Here, we are going to learn about the Acos() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 29, 2021

math.Acos()

The Acos() function is an inbuilt function of the math package which is used to get the arccosine (in radians) of the given value.

It accepts one parameter and returns the arccosine value in radians.

Syntax:

func Acos(x float64) float64

Parameter(s):

  • x : The value whose arccosine value is to be found.

Return Value:

The return type of Acos() function is a float64, it returns the arccosine value (in radians) of the given value.

Special cases are:

  • Acos(x) = NaN if x < -1 or x > 1
    If the parameter is either less than 0 or greater than 0, it returns NaN.

Example 1:

// Golang program to demonstrate the
// example of math.Acos() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Acos(1))
	fmt.Println(math.Acos(0.23))

	fmt.Println(math.Acos(-1))
	fmt.Println(math.Acos(-0.23))

	fmt.Println(math.Acos(-1.23))
	fmt.Println(math.Acos(1.23))

	fmt.Println(math.Acos(-2))
	fmt.Println(math.Acos(2))
}

Output:

0
1.3387186439321834
3.141592653589793
1.8028740096576097
NaN
NaN
NaN
NaN

Example 2:

// Golang program to demonstrate the
// example of math.Acos() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var AcosX float64

	x = 0
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)

	x = 0.23
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)

	x = 1
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)

	x = -0.23
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)

	x = -2
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)

	x = 10
	AcosX = math.Acos(x)
	fmt.Println("Arccosine value of", x, "is", AcosX)
}

Output:

Arccosine value of 0 is 1.5707963267948966
Arccosine value of 0.23 is 1.3387186439321834
Arccosine value of 1 is 0
Arccosine value of -0.23 is 1.8028740096576097
Arccosine value of -2 is NaN
Arccosine value of 10 is NaN

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.