本文整理汇总了Golang中simplemath.Sqrt函数的典型用法代码示例。如果您正苦于以下问题:Golang Sqrt函数的具体用法?Golang Sqrt怎么用?Golang Sqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sqrt函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usge()
return
}
switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("USAGE1:calc add <integer1><integer2>")
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("USAGE2:calc add <integer1><integer2>", err1)
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result1:", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("USAGE3:calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("USAGE4:calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result2:", ret)
default:
Usge()
}
}
示例2: main
func main() {
var args = os.Args
if nil == args || len(args) <= 2 {
fmt.Println("Arguments to less!")
Usage()
os.Exit(0)
}
switch args[1] {
case "add":
if 4 != len(args) {
fmt.Println("USAGE: calc add integer integer")
Usage()
os.Exit(0)
}
a, err1 := strconv.Atoi(args[2])
b, err2 := strconv.Atoi(args[3])
if nil != err1 || nil != err2 {
fmt.Println("Can not convert string to integer!")
Usage()
os.Exit(0)
}
ret := simplemath.Add(a, b)
fmt.Println(a, "+", b, " = ", ret)
case "sqrt":
if 3 != len(args) {
fmt.Println("USAGE: calc sqrt integer")
Usage()
os.Exit(0)
}
a, err := strconv.Atoi(args[2])
if nil != err {
fmt.Println("Can not convert string to integer!")
Usage()
os.Exit(0)
}
ret, err := simplemath.Sqrt(a)
if nil != err {
fmt.Println("Can not use ", a, " in sqrt function!")
Usage()
os.Exit(0)
}
fmt.Println("Sqrt(", a, ") = ", ret)
default:
Usage()
}
}
示例3: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}
switch args[0] {
case "add":
if len(args) != 3 {
showAddUsage()
return
}
//strconv.Atoi: change str into integer
v1, err1 := strconv.Atoi(args[1])
v2, err2 := strconv.Atoi(args[2])
if err1 != nil || err2 != nil {
showAddUsage()
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 2 {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[1])
if err != nil {
showSqrtUsage()
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result: ", ret)
default:
Usage()
}
}
示例4: main
func main() {
args := os.Args[1:]
if args == nil || len(args) < 2 {
Usage()
return
}
//fmt.Println("args 0 is:", args[0], args[1], args[2])
//fmt.Println("length is:", len(args))
/*for i,v := range args {
fmt.Println(i," ", v)
}
*/
switch args[0] {
case "add":
if len(args) != 3 {
fmt.Println("USAGE1: calc add <integer1><integer2>")
return
}
v1, err1 := strconv.Atoi(args[1])
v2, err2 := strconv.Atoi(args[2])
if err1 != nil || err2 != nil {
fmt.Println("USAGE2: calc add <integer1><integer2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 2 {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[1])
if err != nil {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result: ", ret)
default:
Usage()
fmt.Println("why me")
}
}
示例5: main
func main() {
args := os.Args
if args == nil || len(args) < 3 {
Usage()
return
}
switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("Usage: cale add <integer1> <integer2>")
return
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("Usage: cale add <integer1> <integer2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("Usage: calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("Usage: calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result: ", ret)
default:
fmt.Println("unknown command ", args[1])
Usage()
}
}
示例6: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}
fmt.Println("%s\n", args)
switch args[1] {
case "add":
if len(args) != 4 {
ErrAdd()
return
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
ErrAdd()
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("result: %d ", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result: %d ", ret)
default:
Usage()
}
}
示例7: main
func main() {
for i, v := range os.Args {
fmt.Printf("%d:\t%s\n", i, v)
}
args := os.Args[1:]
if args == nil || len(args) < 2 {
Usage()
return
}
switch args[0] {
case "add":
if len(args) != 3 {
fmt.Println("Usage calc add <integer><interger2>")
return
}
v1, err1 := strconv.Atoi(args[1])
v2, err2 := strconv.Atoi(args[2])
if err1 != nil || err2 != nil {
fmt.Println("Usage calc add <integer><interger2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 2 {
fmt.Println("Usage calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[1])
if err != nil {
fmt.Println("Usage calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("ResultL: ", ret)
default:
Usage()
}
}
示例8: main
func main() {
args := os.Args
// fmt.Println(len(args))
if args == nil || len(args) < 2 {
Usage()
return
}
switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("Usage:add 3 8")
return
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("USAGE:add 3 4")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result:", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("sqrt 3-->")
}
v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("这样输入:sqrt 3.")
return
}
ret := simplemath.Sqrt(v)
fmt.Println(ret)
default:
fmt.Println("default")
}
}
示例9: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}
switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("USAGE: calc add <integer1><integer2>")
return
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("USAGE: calc add <integer1><integer2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
if len(args) != 3 {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
v, err := strconv.Atoi(args[2])
if err != nil {
fmt.Println("USAGE: calc sqrt <integer>")
return
}
ret := simplemath.Sqrt(v)
fmt.Println("Result: ", ret)
default:
Usage()
//fmt.Printf("len(args): %d, args[0] : %s , args[1]: %s, args[2]: %d, args[3]: %d",len(args), args[0], args[1], args[2], args[3])
}
}