learning_go/calculator/calculator.go
2025-06-30 06:58:29 +03:00

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
}