dtrn74832 2014-03-04 23:46
浏览 177
已采纳

在go(golang)中获得机器epsilon的最简单方法

What is the easiest way to get the machine epsilon in Go (golang)? What about other aspects of floating point numbers such as precision, min exponent, max exponent, wobble, etc?

I realize that there is the math/const package with the max and min for the different float types (http://golang.org/src/pkg/math/const.go), but no other information.

One reason I would like to know is to verify that I've reached the maximum precision for a given calculation that the machine can do so that I don't quit to early or try longer then needed.

The other is just for curiosity.

Thanks

EDIT:

For the fun I looked up in some notes from school on how to calculate the epsilon manually for the funs and here is a rough translation from c++ http://play.golang.org/p/XOXwIdNfsa enjoy

EDIT: comment from below (thanks for a more idiomatic way of finding epsilon):

Use epsilon := math.Nextafter(1, 2) - 1 PlaygroundNick Craig-Wood Mar 5 at 8:07

  • 写回答

2条回答 默认 最新

  • dongsheng4126335 2014-03-04 23:59
    关注

    It's not defined, I found the issue resolved as "working as intended" on the issue tracker:

    https://code.google.com/p/go/issues/detail?id=966

    The suggestion seems to be to use math.Nextafter to derive the value if you need it.

    Specifically, the formula is math.Nextafter(1.0,2.0)-1.0 (the second argument can be any number greater than 1.0).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来