How to do it...

  1. Open the console and create the folder chapter03/recipe04.
  2. Navigate to the directory.
  3. Create the main.go file with the following content:
        package main

import (
"fmt"
"math/big"
)

const PI = `3.1415926535897932384626433832795028841971693
993751058209749445923078164062862089986280348253
421170679821480865132823066470938446095505822317
253594081284811174502841027019385211055596446229
4895493038196`
const diameter = 3.0
const precision = 400

func main() {

pi, _ := new(big.Float).SetPrec(precision).SetString(PI)
d := new(big.Float).SetPrec(precision).SetFloat64(diameter)

circumference := new(big.Float).Mul(pi, d)

pi64, _ := pi.Float64()
fmt.Printf("Circumference big.Float = %.400f\n",
circumference)
fmt.Printf("Circumference float64 = %.400f\n", pi64*diameter)

sum := new(big.Float).Add(pi, pi)
fmt.Printf("Sum = %.400f\n", sum)

diff := new(big.Float).Sub(pi, pi)
fmt.Printf("Diff = %.400f\n", diff)

quo := new(big.Float).Quo(pi, pi)
fmt.Printf("Quocient = %.400f\n", quo)

}
  1. Execute the code by running go run main.go in the Terminal.
  2. You will see the following output: