Menu Close

Go – How to get the arc tangent of y/x

Here, We will learn how to get the arc tangent of y/x in go. We can get it by using Atan2() function in math package in go golang.

Function prototype:

func Atan2(y, x float64) float64

Return value:

Atan2() function in math package returns
the arc tangent of y/x by using the signs of
the two to determine the quadrant of the
return value.

Example with code:

package main

import (

func main() {

  no := math.Atan2(1, 2)
  fmt.Printf("%.2f\n", no)

  no = math.Atan2(0, 0)
  fmt.Printf("%.2f\n", no)

  no = math.Atan2(1, 4)
  fmt.Printf("%.2f\n", no)

  no = math.Atan2(3, 4)
  fmt.Printf("%.2f\n", no)

  no = math.Atan2(5, 2)
  fmt.Printf("%.2f\n", no)




To learn more about golang, Please refer given below link:

Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us