Go constant: values for untyped Go constants and their operations
Answer: The go/constant package represents untyped Go constants and the operations defined on them, including a special Unknown value.
Values and kinds
A Value stands for an untyped Go constant. Kinds include Bool, String, Int, Float, Complex, and Unknown.
Unknown is used when a value cannot be represented precisely, for example when a number is too large. Operations on unknown values yield unknown values unless the docs say otherwise.
When possible, the smaller, or more precise for floats, representation is chosen.
Operations
Compare requires that the comparison must be defined for the operands.
If the result is not exact, its value is undefined. For an Unknown x, that computed result is 0.
See also
Claims
- id: C1 claim: The package implements values for untyped Go constants and their operations. source: S1 evidence: "Package constant implements Values representing untyped"
- id: C2 claim: Operations on unknown values produce unknown values unless specified otherwise. source: S1 evidence: "Operations on unknown values produce unknown values unless specified otherwise."
- id: C3 claim: If a result is not exact, its value is undefined. source: S2 evidence: "If the result is not exact, its value is undefined."
Sources
- [S1] go/constant. The Go Authors. https://pkg.go.dev/go/constant . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] go/constant source. The Go Authors. https://go.dev/src/go/constant/value.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/constant; The Go Authors, go/constant source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, go/constant; The Go Authors, go/constant source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go constant: values for untyped Go constants and their operations." iinventedlight Library, iil:note:em8hcfnk, version of 2026-11-26. https://iinventedlight.com/library/notes/go-constant/. License: CC-BY-4.0.
@misc{iil_note_em8hcfnk,
author = {{iinventedlight}},
title = {{Go constant: values for untyped Go constants and their operations}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-constant/},
note = {Permanent ID iil:note:em8hcfnk. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-constant.schema.json (schema; CC-BY-4.0)
- go-constant.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-constant.md.