The Computer Language
24.04 Benchmarks Game

too simple Go program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
*/

package main
import ("fmt"; "flag"; "strconv")

func main () {
    n := 0
    flag.Parse()
    if flag.NArg() > 0 { n,_ = strconv.Atoi( flag.Arg(0) ) }
     sum := 0.0
     flip := -1.0
     for i := 1; i <= n; i++ {    
         flip *= -1.0        
         sum += flip / float64(2*i - 1)               
     }                        
    fmt.Printf("%0.9f\n", sum*4.0) 
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
go version go1.22.0 linux/amd64
GOAMD64=v2


 Sat, 02 Mar 2024 00:03:13 GMT

MAKE:
/opt/src/go1.22.0/go/bin/go build -o toosimple.go_run toosimple.go

4.98s to complete and log all make actions

COMMAND LINE:
 ./toosimple.go_run 10000000000

PROGRAM OUTPUT:
3.141592653