doumu2172 2017-02-13 09:07 采纳率: 0%
浏览 510
已采纳

为什么math.Pow10(e int)返回float64而不是int64?

Since parameter e is int, why not just return an int64? Is there any special reason for this?

  • 写回答

1条回答 默认 最新

  • douliao8402 2017-02-13 09:12
    关注

    2 reasons:

    First, the parameter may be negative too, in which case the result is a fraction number between 0 and 1, so a float64 return value is not just justified but needed.

    fmt.Println(math.Pow10(-1))
    

    Output (try it on the Go Playground):

    0.1
    

    Second, almost* every function of the math package returns value(s) of type float64, adding one that doesn't would break "consistency".

    [*] Few exceptions include functions like Float32frombits() and llogb() where the deviation is justified.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 Qcustomplot绘制实时动态曲线
  • ¥20 运用matlab画x-y图
  • ¥15 用idea运行项目,运行tomcat报错:断言失败
  • ¥15 Sqlserver查询链接服务器数据问题
  • ¥15 Bibtex4Word 引用中文文献
  • ¥20 用opencv c/c++ 转换成灰度图,然后做一下直方图均衡,输出mp4文件
  • ¥20 matlab中的双层数值积分
  • ¥50 服务器打印水晶报表问题
  • ¥30 gradle环境下javafx项目如何使用druid连接池
  • ¥15 服务器打印水晶报表问题