本文整理汇总了Golang中simplemath.Add函数的典型用法代码示例。如果您正苦于以下问题:Golang Add函数的具体用法?Golang Add怎么用?Golang Add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
args := os.Args[1:]
opt := args[0]
switch opt {
case "add":
r1, err1 := strconv.Atoi(args[1])
r2, err2 := strconv.Atoi(args[2])
if err1 != nil || err2 != nil {
fmt.Println("add strconv error", r1, r2)
}
res := simplemath.Add(r1, r2)
fmt.Println(res)
/*
case "sqrt" :
r1, err1 := strconv.Atoi(arg[1])
if(err1 != nil){
fmt.Println("sqrt strconv err", err1)
}
res := simplemath.sqrt(r1)
fmt.Println(res)
*/
default:
Usage()
}
}
示例2: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}
fmt.Println(len(args))
fmt.Println(args[0])
fmt.Println(args[1])
fmt.Println(args[2])
switch args[1] {
case "add":
if len(args) != 4 {
fmt.Println("USAGE: calc add <int1> <int2>")
return
}
v1, err1 := strconv.Atoi(args[2])
v2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("USAGE: calc add <int1> <int2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
default:
fmt.Println("Unknown command")
}
}
示例3: 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()
}
}
示例4: main
func main() {
he := &oop.Person{"hezuoxiang", 10}
he.Say("fuck")
var a oop.Integer = 1
var b oop.Number = &a
fmt.Println("Result: ", b.Less(2))
fmt.Println("Result: ", simplemath.Add(3, 4))
}
示例5: 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()
}
}
示例6: 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()
}
}
示例7: 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")
}
}
示例8: 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()
}
}
示例9: main
func main() {
args := os.Args
switch args[0] {
case "add":
if len(args) != 3 {
fmt.Println("USAGE: calc add <integer1><integer2>")
return
}
v1, err1 := strconv.Atoi(args[1])
v2, err2 := strconv.Atoi(args[2])
if err1 != nil || err2 != nil {
fmt.Println("USAGE: calc add <integer1><integer2>")
return
}
ret := simplemath.Add(v1, v2)
fmt.Println("Result: ", ret)
case "sqrt":
fmt.Println("sqrt")
}
}
示例10: 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()
}
}
示例11: main
func main() {
args := os.Args
if args == nil || len(args) < 2 {
Usage()
return
}
switch args[1] {
case "add":
arg1, err1 := strconv.Atoi(args[2])
arg2, err2 := strconv.Atoi(args[3])
if err1 != nil || err2 != nil {
fmt.Println("err")
return
}
ret := simplemath.Add(arg1, arg2)
fmt.Println("Return ", ret)
case "sqrt":
default:
Usage()
}
}
示例12: 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()
}
}
示例13: 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])
}
}
示例14: 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")
}
}
示例15: main
func main() {
args := os.Args
if 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)
default:
Usage()
}
}