如何声明任意位模式的浮点型Go常量?

In Go I can declare a typed float constant like this:

const foo float64 = 1e100

or a float variable of arbitrary bit pattern like this:

var bar = math.Float64frombits(0x7ff8c0c0ac0ffee1)

But this is an error ("const initializer… is not a constant"):

const baz = math.Float64frombits(0x7ff8c0c0ac0ffee1)

How might I declare a typed float const of arbitrary bit pattern?

Your call to Math.Float64frombits occurs at runtime, not compile time, and thus, is not constant. From the effective Go page (which will explain it better than I can):

Constants in Go are just that—constant. They are created at compile time, even when defined as locals in functions, and can only be numbers, strings or booleans. Because of the compile-time restriction, the expressions that define them must be constant expressions, evaluatable by the compiler. For instance, 1<<3 is a constant expression, while math.Sin(math.Pi/4) is not because the function call to math.Sin needs to happen at run time.

Link: https://golang.org/doc/effective_go.html#constants

You can't call a function like Float64frombits in a constant declaration; the function call means it can't be evaluated fully at compile time, so it can't be used as a constant. You can, however, just dump bits into a float value:

const myFloat float64 = 0x7ff8c0c0ac0ffee1

func main() {
    fmt.Println(myFloat)
}

If you want to store the bit value (which is essentially a uint64), and have it available as a float64 to external packages, you can provide a "constant" function, which you guarantee to only return the constant value. This is precisely how functions like math.NaN work.

const uintFoo = 0x7ff8c0c0ac0ffee1

func ConstFoo() float64 {
    return math.Float64frombits(uintFoo)
}