O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe10.
  2. Navigate to the directory.
  3. Create the radians.go file with the following content:
        package main        import (          "fmt"          "math"        )        type Radian float64        func (rad Radian) ToDegrees() Degree {          return Degree(float64(rad) * (180.0 / math.Pi))        }        func (rad Radian) Float64() float64 {          return float64(rad)        }        type Degree float64         func (deg Degree) ToRadians() Radian {          return Radian(float64(deg) * (math.Pi / 180.0))        }        func (deg Degree) Float64() float64 {          return float64(deg)        }        func main() {          val := radiansToDegrees(1)          fmt.Printf("One radian is : %.4f degrees\n", val)          val2 := degreesToRadians(val)          fmt.Printf("%.4f degrees is %.4f rad\n", val, val2)          // Conversion as part // of type methods ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required