Home »
Golang »
Golang Reference
Golang math.Atan() Function with Examples
Golang | math.Atan() Function: Here, we are going to learn about the Atan() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 29, 2021
math.Atan()
The Atan() function is an inbuilt function of the math package which is used to get the arctangent value (in radians) of the given value.
It accepts one parameter and returns the arctangent (in radians).
Syntax
func Atan(x float64) float64
Parameters
- x : The value whose arctangent value is to be found.
Return Value
The return type of Atan() function is a float64, it returns the arctangent value (in radians) of the given value.
Special cases are:
- Atan(±0) = ±0
If the parameter is either positive or negative zero (±0), it returns the same (±0).
- Atan(±Inf) = ±Pi/2
If the parameter is either positive or negative infinity (±Inf), it returns ±Pi/2.
Example 1
// Golang program to demonstrate the
// example of math.Atan() Function
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Atan(1))
fmt.Println(math.Atan(0.23))
fmt.Println(math.Atan(-1))
fmt.Println(math.Atan(-0.23))
fmt.Println(math.Atan(-1.23))
fmt.Println(math.Atan(1.23))
fmt.Println(math.Atan(-0))
fmt.Println(math.Atan(0))
fmt.Println(math.Atan(math.Inf(-1)))
fmt.Println(math.Atan(math.Inf(1)))
}
Output:
0.7853981633974483
0.22606838799388393
-0.7853981633974483
-0.22606838799388393
-0.8881737743776795
0.8881737743776795
0
0
-1.5707963267948966
1.5707963267948966
Example 2
// Golang program to demonstrate the
// example of math.Atan() Function
package main
import (
"fmt"
"math"
)
func main() {
var x float64
var AtanX float64
x = 0
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = 0.23
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = 1
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = -0.23
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = -2
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = 10
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = math.Inf(-1)
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
x = math.Inf(1)
AtanX = math.Atan(x)
fmt.Println("Arctangent value of", x, "is", AtanX)
}
Output:
Arctangent value of 0 is 0
Arctangent value of 0.23 is 0.22606838799388393
Arctangent value of 1 is 0.7853981633974483
Arctangent value of -0.23 is -0.22606838799388393
Arctangent value of -2 is -1.1071487177940904
Arctangent value of 10 is 1.4711276743037345
Arctangent value of -Inf is -1.5707963267948966
Arctangent value of +Inf is 1.5707963267948966
Golang math Package Constants and Functions »