I am trying to solve this: http://tour.golang.org/#58
Here is what I have done:
#imports omitted
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return "Cannot Sqrt negative number: " + string(e)
}
func Sqrt(f float64) (float64, error) {
if f < 0 {
return 0, ErrNegativeSqrt(1)
}
# calculate z here...
return z, nil
}
# main omitted
I have also tried e.String() and e.string() but those didn't work too.
Try using the fmt package
import "fmt"
...
return fmt.Sprint("Cannot Sqrt negative number ", float64(e))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With