go-tour/if.go

18 lines
218 B
Go
Raw Normal View History

2020-02-05 03:44:36 +00:00
package main
import (
"fmt"
"math"
)
func sqrt(x float64) string {
if x < 0 {
return sqrt(-x) + "i"
}
return fmt.Sprint(math.Sqrt(x))
}
func main() {
fmt.Println(sqrt(2), sqrt(-4))
}