25 lines
442 B
Go
Executable File
25 lines
442 B
Go
Executable File
// Package calculator does simple calculations.
|
|
package calculator // Add takes two numbers and returns the result of adding them together.
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
func Add(a, b int) int {
|
|
return a + b
|
|
}
|
|
|
|
func Subtract(a, b int) int {
|
|
return a - b
|
|
}
|
|
|
|
func Multiply(a, b int) int {
|
|
return a * b
|
|
}
|
|
|
|
func Divide(a, b int) (int, error) {
|
|
if b == 0 {
|
|
return 0, errors.New("division by zero not allowed")
|
|
}
|
|
return a / b, nil
|
|
} |