A Tour of Go, problem #56 - error handling New to Go, trying to solve Tour of Go, Exercise 56, which is about error handling.

Can the following error handling method can be further improved?

package main

import (
    "fmt"
    "math"
)

type ErrNegativeSqrt float64

func (e ErrNegativeSqrt) Error() string {
    return fmt.Sprintf("cannot Sqrt negative number: %f", float64(e))
}

func Sqrt(f float64) (float64, error) {
    if f &gt; 0 {
        return math.Sqrt(f), nil
    } else {
        return 0, ErrNegativeSqrt(f)
    }
}

func main() {
    fmt.Println(Sqrt(2))
    fmt.Println(Sqrt(-2))
}
I would name the error ErrSqrtNegative instead of ErrNegativeSqrt.

Sqrt(0) should not be an error.

In case of error, I would use math.NaN(), ErrSqrtNegative(f) as the return values.