您如何从Go中的int转换溢出中得到错误?

I'm looking for integer conversion functions resembling this:

func narrow(x int64) (int32, error) { ... }

In this example, the function would return ((int32)(x), nil) if x fits into an int32, and (nil, someError) if it doesn't.

There seem to be a lot of conversions built into the language, but they all silently swallow overflows, rather than providing a reified error. Am I missing something?

查看全部
dsedug8644
dsedug8644
2016/09/20 20:15
  • int
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复