go/constant

Guided tour · Go Tooling · pkg.go.dev →

Arbitrary-precision values used by go/types for untyped constants (ints, rationals, strings, booleans).

Usage

Build and operate

a := constant.MakeInt64(7)
b := constant.MakeInt64(3)
sum := constant.BinaryOp(a, token.ADD, b) // 10
fmt.Println(constant.Int64Val(sum))