27 lines
511 B
Go
27 lines
511 B
Go
package operator
|
|
|
|
import "fmt"
|
|
|
|
// Add returns the sum of a and b.
|
|
func Add(a, b int) int {
|
|
return a + b
|
|
}
|
|
|
|
// Sub returns the difference a - b.
|
|
func Sub(a, b int) int {
|
|
return a - b
|
|
}
|
|
|
|
// Mul returns the product of a and b.
|
|
func Mul(a, b int) int {
|
|
return a * b
|
|
}
|
|
|
|
// Div returns the division a / b as float64. Returns an error on division by zero.
|
|
func Div(a, b int) (float64, error) {
|
|
if b == 0 {
|
|
return 0, fmt.Errorf("divide by zero")
|
|
}
|
|
return float64(a) / float64(b), nil
|
|
}
|