在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

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).

Equation to use

The above works for any binary floating point type (e.g. the Go types you are referring to.)

package main

import "fmt"

func main() {
    f32 := float32(7.)/3 - float32(4.)/3 - float32(1.)
    fmt.Println(f32)

    f64 := float64(7.)/3 - float64(4.)/3 - float64(1.)
    fmt.Println(f64)
}

gives:

-1.1920929e-07
2.220446049250313e-16

taking the absolute (unsigned) value of f32 yields the correct machine ε.

Edit: As mentioned below in a comment from SGJ, this would not work on decimal floating point types, but as far as I'm aware they have not been implemented yet in Golang.