1 Star 0 Fork 0

暗夜之学 / gostudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 399 Bytes
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
hanjian 提交于 2020-11-15 23:05 . effective
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) String() string {
return fmt.Sprint(e)
}
func Sqrt(x float64) (float64, error) {
if x < 0 {
return 0, ErrNegativeSqrt(x)
}
return 0, nil
}
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %f", e)
}
func main() {
fmt.Println(Sqrt(2))
fmt.Println(Sqrt(-2))
}
Go
1
https://gitee.com/lovehei/gostudy.git
git@gitee.com:lovehei/gostudy.git
lovehei
gostudy
gostudy
73c713180039

搜索帮助