CINXE.COM

constant package - go/constant - Go Packages

<!DOCTYPE html> <html lang="en" data-layout="responsive" data-local=""> <head> <script> window.addEventListener('error', window.__err=function f(e){f.p=f.p||[];f.p.push(e)}); </script> <script> (function() { const theme = document.cookie.match(/prefers-color-scheme=(light|dark|auto)/)?.[1] if (theme) { document.querySelector('html').setAttribute('data-theme', theme); } }()) </script> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="Description" content="Package constant implements Values representing untyped Go constants and their corresponding operations."> <meta class="js-gtmID" data-gtmid="GTM-W8MVQXG"> <link rel="shortcut icon" href="/static/shared/icon/favicon.ico"> <link rel="canonical" href="https://pkg.go.dev/go/constant"> <link href="/static/frontend/frontend.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Go Packages"> <title>constant package - go/constant - Go Packages</title> <link href="/static/frontend/unit/unit.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> <link href="/static/frontend/unit/main/main.min.css?version=prod-frontend-00090-vzc" rel="stylesheet"> </head> <body> <script> function loadScript(src, mod = true) { let s = document.createElement('script'); s.src = src; if (mod) { s.type = 'module'; s.async = true; s.defer = true } document.head.appendChild(s); } loadScript("/third_party/dialog-polyfill/dialog-polyfill.js", false) loadScript("/static/frontend/frontend.js"); </script> <header class="go-Header go-Header--full js-siteHeader"> <div class="go-Header-inner go-Header-inner--dark"> <nav class="go-Header-nav"> <a href="https://go.dev/" class="js-headerLogo" data-gtmc="nav link" data-test-id="go-header-logo-link" role="heading" aria-level="1"> <img class="go-Header-logo" src="/static/shared/logo/go-white.svg" alt="Go"> </a> <div class="skip-navigation-wrapper"> <a class="skip-to-content-link" aria-label="Skip to main content" href="#main-content"> Skip to Main Content </a> </div> <div class="go-Header-rightContent"> <div class="go-SearchForm js-searchForm"> <form class="go-InputGroup go-ShortcutKey go-SearchForm-form" action="/search" data-shortcut="/" data-shortcut-alt="search" data-gtmc="search form" aria-label="Search for a package" role="search" > <input name="q" class="go-Input js-searchFocus" aria-label="Search for a package" type="search" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="Search packages or symbols" value="" /> <input name="m" value="" hidden> <button class="go-Button go-Button--inverted" aria-label="Submit search"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt="" /> </button> </form> <button class="go-SearchForm-expandSearch js-expandSearch" data-gtmc="nav button" aria-label="Open search" data-test-id="expand-search"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt=""> </button> </div> <ul class="go-Header-menu"> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Why Go <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--why js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#case-studies"> </span>Case Studies</span> </a> </div> <p>Common problems companies solve with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/solutions#use-cases"> </span>Use Cases</span> </a> </div> <p>Stories about how and why companies use Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/security/policy/"> </span>Security Policy</span> </a> </div> <p>How Go can help keep you secure by default</p> </li> </ul> </li> <li class="go-Header-menuItem"> <a href="https://go.dev/learn/" data-gtmc="nav link">Learn</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Docs <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--docs js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/effective_go"> <span>Effective Go</span> </a> </div> <p>Tips for writing clear, performant, and idiomatic Go code</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/"> <span>Go User Manual</span> </a> </div> <p>A complete introduction to building software with Go</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://pkg.go.dev/std"> <span>Standard library</span> </a> </div> <p>Reference documentation for Go's standard library</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/doc/devel/release"> <span>Release Notes</span> </a> </div> <p>Learn what's new in each Go release</p> </li> </ul> </li> <li class="go-Header-menuItem go-Header-menuItem--active"> <a href="/" data-gtmc="nav link">Packages</a> </li> <li class="go-Header-menuItem"> <a class="js-desktop-menu-hover" href="#" data-gtmc="nav link"> Community <img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_drop_down_gm_grey_24dp.svg" alt="submenu dropdown icon"> </a> <ul class="go-Header-submenu go-Header-submenu--community js-desktop-submenu-hover" aria-label="submenu"> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/talks/"> <span>Recorded Talks</span> </a> </div> <p>Videos from prior events</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://www.meetup.com/pro/go"> <span>Meetups</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Meet other local Go developers</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://github.com/golang/go/wiki/Conferences"> <span>Conferences</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </div> <p>Learn and network with Go developers from around the world</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/blog"> <span>Go blog</span> </a> </div> <p>The Go project's official blog.</p> </li> <li class="go-Header-submenuItem"> <div> <a href="https://go.dev/help"> <span>Go project</span> </a> </div> <p>Get help and stay informed from Go</p> </li> <li class="go-Header-submenuItem"> <div> Get connected </div> <p></p> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" aria-label="Get connected with google-groups (Opens in new window)" href="https://groups.google.com/g/golang-nuts" ><img src="/static/shared/logo/social/google-groups.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with github (Opens in new window)" href="https://github.com/golang"><img src="/static/shared/logo/social/github.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with twitter (Opens in new window)" href="https://twitter.com/golang"><img src="/static/shared/logo/social/twitter.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with reddit (Opens in new window)" href="https://www.reddit.com/r/golang/"><img src="/static/shared/logo/social/reddit.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with slack (Opens in new window)" href="https://invite.slack.golangbridge.org/"><img src="/static/shared/logo/social/slack.svg" /></a> <a class="go-Header-socialIcon" aria-label="Get connected with stack-overflow (Opens in new window)" href="https://stackoverflow.com/collectives/go"><img src="/static/shared/logo/social/stack-overflow.svg" /></a> </div> </li> </ul> </li> </ul> <button class="go-Header-navOpen js-headerMenuButton go-Header-navOpen--white" data-gtmc="nav button" aria-label="Open navigation"> </button> </div> </nav> </div> </header> <aside class="go-NavigationDrawer js-header"> <nav class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="https://go.dev/"> <img class="go-NavigationDrawer-logo" src="/static/shared/logo/go-blue.svg" alt="Go."> </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Why Go</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Why Go </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#case-studies"> Case Studies </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/solutions#use-cases"> Use Cases </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/security/policy/"> Security Policy </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/learn/">Learn</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Docs</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"><i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Docs </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/effective_go"> Effective Go </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/"> Go User Manual </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://pkg.go.dev/std"> Standard library </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/doc/devel/release"> Release Notes </a> </li> </ul> </div> </div> </li> <li class="go-NavigationDrawer-listItem go-NavigationDrawer-listItem--active"> <a href="/">Packages</a> </li> <li class="go-NavigationDrawer-listItem js-mobile-subnav-trigger go-NavigationDrawer-hasSubnav"> <a href="#"> <span>Community</span> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_next_gm_grey_24dp.svg" alt=""> </i> </a> <div class="go-NavigationDrawer go-NavigationDrawer-submenuItem"> <div class="go-NavigationDrawer-nav"> <div class="go-NavigationDrawer-header"> <a href="#"> <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/navigate_before_gm_grey_24dp.svg" alt=""> </i> Community </a> </div> <ul class="go-NavigationDrawer-list"> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/talks/"> Recorded Talks </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://www.meetup.com/pro/go"> Meetups <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://github.com/golang/go/wiki/Conferences"> Conferences <i class="material-icons"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/launch_gm_grey_24dp.svg" alt=""> </i> </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/blog"> Go blog </a> </li> <li class="go-NavigationDrawer-listItem"> <a href="https://go.dev/help"> Go project </a> </li> <li class="go-NavigationDrawer-listItem"> <div>Get connected</div> <div class="go-Header-socialIcons"> <a class="go-Header-socialIcon" href="https://groups.google.com/g/golang-nuts"><img src="/static/shared/logo/social/google-groups.svg" /></a> <a class="go-Header-socialIcon" href="https://github.com/golang"><img src="/static/shared/logo/social/github.svg" /></a> <a class="go-Header-socialIcon" href="https://twitter.com/golang"><img src="/static/shared/logo/social/twitter.svg" /></a> <a class="go-Header-socialIcon" href="https://www.reddit.com/r/golang/"><img src="/static/shared/logo/social/reddit.svg" /></a> <a class="go-Header-socialIcon" href="https://invite.slack.golangbridge.org/"><img src="/static/shared/logo/social/slack.svg" /></a> <a class="go-Header-socialIcon" href="https://stackoverflow.com/collectives/go"><img src="/static/shared/logo/social/stack-overflow.svg" /></a> </div> </li> </ul> </div> </div> </li> </ul> </nav> </aside> <div class="go-NavigationDrawer-scrim js-scrim" role="presentation"></div> <main class="go-Main" id="main-content"> <div class="go-Main-banner" role="alert"></div> <header class="go-Main-header js-mainHeader"> <nav class="go-Main-headerBreadcrumb go-Breadcrumb" aria-label="Breadcrumb" data-test-id="UnitHeader-breadcrumb"> <ol> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/" data-gtmc="breadcrumb link">Discover Packages</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/std" data-gtmc="breadcrumb link">Standard library</a> </li> <li data-test-id="UnitHeader-breadcrumbItem"> <a href="/go@go1.23.3" data-gtmc="breadcrumb link">go</a> </li> <li> <a href="/go/constant@go1.23.3" data-gtmc="breadcrumb link" aria-current="location" data-test-id="UnitHeader-breadcrumbCurrent"> constant </a> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;go/constant" aria-label="Copy Path to Clipboard" data-to-copy="go/constant" data-gtmc="breadcrumbs button" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" > </button> </li> </ol> </nav> <div class="go-Main-headerContent"> <div class="go-Main-headerTitle js-stickyHeader"> <a class="go-Main-headerLogo" href="https://go.dev/" aria-hidden="true" tabindex="-1" data-gtmc="header link" aria-label="Link to Go Homepage"> <img height="78" width="207" src="/static/shared/logo/go-blue.svg" alt="Go"> </a> <h1 class="UnitHeader-titleHeading" data-test-id="UnitHeader-title">constant</h1> <span class="go-Chip go-Chip--inverted">package</span> <span class="go-Chip go-Chip--inverted">standard library</span> <button class="go-Button go-Button--inline go-Clipboard js-clipboard" title="Copy path to clipboard.&#10;&#10;go/constant" aria-label="Copy Path to Clipboard" data-to-copy="go/constant" data-gtmc="title button" tabindex="-1" > <img class="go-Icon go-Icon--accented" height="24" width="24" src="/static/shared/icon/content_copy_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Main-headerDetails"> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-version"> <a href="?tab=versions" aria-label="Version: go1.23.3" data-gtmc="header link" aria-describedby="version-description"> <span class="go-textSubtle" aria-hidden="true">Version: </span> go1.23.3 </a> <div class="screen-reader-only" id="version-description" hidden> Opens a new window with list of versions in this module. </div> <span class="DetailsHeader-badge--latest" data-test-id="UnitHeader-minorVersionBanner"> <span class="go-Chip DetailsHeader-span--latest">Latest</span> <span class="go-Chip DetailsHeader-span--notAtLatest"> Latest <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/alert_gm_grey_24dp.svg" alt="Warning"> </summary> <p>This package is not in the latest version of its module.</p> </details> </span> <a href="/go/constant" aria-label="Go to Latest Version" data-gtmc="header link"> <span class="go-Chip go-Chip--alert DetailsHeader-span--goToLatest">Go to latest</span> </a> </span> </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-commitTime"> Published: Nov 6, 2024 </span> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-licenses"> License: <a href="/go/constant@go1.23.3?tab=licenses" data-test-id="UnitHeader-license" data-gtmc="header link" aria-describedby="license-description">BSD-3-Clause</a> </span> <div class="screen-reader-only" id="license-description" hidden> Opens a new window with license information. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-imports"> <a href="/go/constant@go1.23.3?tab=imports" aria-label="Imports: 9" data-gtmc="header link" aria-describedby="imports-description"> <span class="go-textSubtle">Imports: </span>9 </a> </span> <div class="screen-reader-only" id="imports-description" hidden> Opens a new window with list of imports. </div> <span class="go-Main-headerDetailItem" data-test-id="UnitHeader-importedby"> <a href="/go/constant@go1.23.3?tab=importedby" aria-label="Imported By: 3,551" data-gtmc="header link" aria-describedby="importedby-description"> <span class="go-textSubtle">Imported by: </span>3,551 </a> </span> <div class="screen-reader-only" id="importedby-description" hidden> Opens a new window with list of known importers. </div> </div> <div class="UnitHeader-overflowContainer"> <svg class="UnitHeader-overflowImage" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> <path d="M0 0h24v24H0z" fill="none"/> <path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/> </svg> <select class="UnitHeader-overflowSelect js-selectNav" tabindex="-1"> <option value="/">Main</option> <option value="/go/constant@go1.23.3?tab=versions"> Versions </option> <option value="/go/constant@go1.23.3?tab=licenses"> Licenses </option> <option value="/go/constant@go1.23.3?tab=imports"> Imports </option> <option value="/go/constant@go1.23.3?tab=importedby"> Imported By </option> </select> </div> </div> </header> <aside class="go-Main-aside js-mainAside"> <div class="UnitMeta"> <h2 class="go-textLabel">Details</h2> <ul class="UnitMeta-details"> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Valid <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/go.mod" target="_blank" rel="noopener">go.mod</a> file <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p> The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Redistributable license <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p> Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed. </p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Tagged version <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p>Modules with tagged versions give importers more predictable builds.</p> </details> </li> <li> <details class="go-Tooltip js-tooltip" data-gtmc="tooltip"> <summary class="go-textSubtle"> <img class="go-Icon go-Icon--accented"src="/static/shared/icon/check_circle_gm_grey_24dp.svg" alt="checked"height="24" width="24"> Stable version <img class="go-Icon" src="/static/shared/icon/help_gm_grey_24dp.svg" alt="" height="24" width="24"> </summary> <p>When a project reaches major version v1 it is considered stable.</p> </details> </li> <li class="UnitMeta-detailsLearn"> <a href="/about#best-practices" data-gtmc="meta link">Learn more about best practices</a> </li> </ul> <h2 class="go-textLabel">Repository</h2> <div class="UnitMeta-repo"> <a href="https://cs.opensource.google/go/go" title="https://cs.opensource.google/go/go" target="_blank" rel="noopener"> cs.opensource.google/go/go </a> </div> <h2 class="go-textLabel">Links</h2> <ul class="UnitMeta-links"> <li> <a href="https://go.dev/security/policy" title="Report security issues in the Go standard library and sub-repositories"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/security_grey_24dp.svg" alt=""> Report a Vulnerability </a> </li> </ul> </div> </aside> <nav class="go-Main-nav go-Main-nav--sticky js-mainNav" aria-label="Outline"> <div class="go-Main-navDesktop"> <div class="UnitOutline-jumpTo"> <button class="UnitOutline-jumpToInput go-ShortcutKey js-jumpToInput" aria-controls="jump-to-modal" aria-label="Open Jump to Identifier" data-shortcut="f" data-shortcut-alt="find" data-test-id="jump-to-button" data-gtmc="outline button"> Jump to ... </button> </div> <ul class="go-Tree js-tree" role="tree" aria-label="Outline"> <li> <a href="#section-documentation" data-gtmc="outline link"> Documentation </a> <ul> <li> <a href="#pkg-overview" data-gtmc="doc outline link">Overview</a> </li> <li class="DocNav-overview"> <a href="#pkg-index" data-gtmc="doc outline link"> Index </a> <ul> <li> <a href="#pkg-examples" data-gtmc="doc outline link"> Examples </a> </li> </ul> </li> <li class="DocNav-constants"> <a href="#pkg-constants" data-gtmc="doc outline link"> Constants </a> </li> <li class="DocNav-variables"> <a href="#pkg-variables" data-gtmc="doc outline link"> Variables </a> </li> <li class="DocNav-functions"> <a href="#pkg-functions" data-gtmc="doc outline link"> Functions </a> <ul> <li> <a href="#BitLen" title="BitLen(x)" data-gtmc="doc outline link"> BitLen(x) </a> </li> <li> <a href="#BoolVal" title="BoolVal(x)" data-gtmc="doc outline link"> BoolVal(x) </a> </li> <li> <a href="#Bytes" title="Bytes(x)" data-gtmc="doc outline link"> Bytes(x) </a> </li> <li> <a href="#Compare" title="Compare(x_, op, y_)" data-gtmc="doc outline link"> Compare(x_, op, y_) </a> </li> <li> <a href="#Float32Val" title="Float32Val(x)" data-gtmc="doc outline link"> Float32Val(x) </a> </li> <li> <a href="#Float64Val" title="Float64Val(x)" data-gtmc="doc outline link"> Float64Val(x) </a> </li> <li> <a href="#Int64Val" title="Int64Val(x)" data-gtmc="doc outline link"> Int64Val(x) </a> </li> <li> <a href="#Sign" title="Sign(x)" data-gtmc="doc outline link"> Sign(x) </a> </li> <li> <a href="#StringVal" title="StringVal(x)" data-gtmc="doc outline link"> StringVal(x) </a> </li> <li> <a href="#Uint64Val" title="Uint64Val(x)" data-gtmc="doc outline link"> Uint64Val(x) </a> </li> <li> <a href="#Val" title="Val(x)" data-gtmc="doc outline link"> Val(x) </a> </li> </ul> </li> <li class="DocNav-types"> <a href="#pkg-types" data-gtmc="doc outline link"> Types </a> <ul> <li> <a href="#Kind" title="type Kind" data-gtmc="doc outline link"> type Kind </a> <ul> <li> <a href="#Kind.String" title="(i) String()" data-gtmc="doc outline link"> (i) String() </a> </li> </ul> </li> <li> <a href="#Value" title="type Value" data-gtmc="doc outline link"> type Value </a> <ul> <li> <a href="#BinaryOp" title="BinaryOp(x_, op, y_)" data-gtmc="doc outline link"> BinaryOp(x_, op, y_) </a> </li> <li> <a href="#Denom" title="Denom(x)" data-gtmc="doc outline link"> Denom(x) </a> </li> <li> <a href="#Imag" title="Imag(x)" data-gtmc="doc outline link"> Imag(x) </a> </li> <li> <a href="#Make" title="Make(x)" data-gtmc="doc outline link"> Make(x) </a> </li> <li> <a href="#MakeBool" title="MakeBool(b)" data-gtmc="doc outline link"> MakeBool(b) </a> </li> <li> <a href="#MakeFloat64" title="MakeFloat64(x)" data-gtmc="doc outline link"> MakeFloat64(x) </a> </li> <li> <a href="#MakeFromBytes" title="MakeFromBytes(bytes)" data-gtmc="doc outline link"> MakeFromBytes(bytes) </a> </li> <li> <a href="#MakeFromLiteral" title="MakeFromLiteral(lit, tok, zero)" data-gtmc="doc outline link"> MakeFromLiteral(lit, tok, zero) </a> </li> <li> <a href="#MakeImag" title="MakeImag(x)" data-gtmc="doc outline link"> MakeImag(x) </a> </li> <li> <a href="#MakeInt64" title="MakeInt64(x)" data-gtmc="doc outline link"> MakeInt64(x) </a> </li> <li> <a href="#MakeString" title="MakeString(s)" data-gtmc="doc outline link"> MakeString(s) </a> </li> <li> <a href="#MakeUint64" title="MakeUint64(x)" data-gtmc="doc outline link"> MakeUint64(x) </a> </li> <li> <a href="#MakeUnknown" title="MakeUnknown()" data-gtmc="doc outline link"> MakeUnknown() </a> </li> <li> <a href="#Num" title="Num(x)" data-gtmc="doc outline link"> Num(x) </a> </li> <li> <a href="#Real" title="Real(x)" data-gtmc="doc outline link"> Real(x) </a> </li> <li> <a href="#Shift" title="Shift(x, op, s)" data-gtmc="doc outline link"> Shift(x, op, s) </a> </li> <li> <a href="#ToComplex" title="ToComplex(x)" data-gtmc="doc outline link"> ToComplex(x) </a> </li> <li> <a href="#ToFloat" title="ToFloat(x)" data-gtmc="doc outline link"> ToFloat(x) </a> </li> <li> <a href="#ToInt" title="ToInt(x)" data-gtmc="doc outline link"> ToInt(x) </a> </li> <li> <a href="#UnaryOp" title="UnaryOp(op, y, prec)" data-gtmc="doc outline link"> UnaryOp(op, y, prec) </a> </li> </ul> </li> </ul> </li> </ul> </li> <li> <a href="#section-sourcefiles" data-gtmc="outline link"> Source Files </a> </li> </ul> </div> <div class="go-Main-navMobile js-mainNavMobile"> <label class="go-Label"> <select class="go-Select"> <option selected disabled>Documentation</option> </select> </label> </div> </nav> <article class="go-Main-article js-mainContent"> <div class="UnitDetails" data-test-id="UnitDetails" style="display: block;"> <div class="UnitDetails-content js-unitDetailsContent" data-test-id="UnitDetails-content"> <div class="UnitDoc"> <h2 class="UnitDoc-title" id="section-documentation"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/code_gm_grey_24dp.svg" alt=""> Documentation <a class="UnitDoc-idLink" href="#section-documentation" aria-label="Go to Documentation">露</a> </h2> <div class="Documentation js-documentation"> <div class="Documentation-content js-docContent"> <section class="Documentation-overview"> <h3 tabindex="-1" id="pkg-overview" class="Documentation-overviewHeader">Overview <a href="#pkg-overview" aria-label="Go to Overview">露</a></h3> <p>Package constant implements Values representing untyped Go constants and their corresponding operations. </p><p>A special Unknown value may be used when a value is unknown due to an error. Operations on unknown values produce unknown values unless specified otherwise. </p> <details tabindex="-1" id="example-package-ComplexNumbers" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example (ComplexNumbers) <a href="#example-package-ComplexNumbers" aria-label="Go to Example (ComplexNumbers)">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;go/token&#34; ) func main() { // Create the complex number 2.3 + 5i. ar := constant.MakeFloat64(2.3) ai := constant.MakeImag(constant.MakeInt64(5)) a := constant.BinaryOp(ar, token.ADD, ai) // Compute (2.3 + 5i) * 11. b := constant.MakeUint64(11) c := constant.BinaryOp(a, token.MUL, b) // Convert c into a complex128. Ar, exact := constant.Float64Val(constant.Real(c)) if !exact { fmt.Printf(&#34;Could not represent real part %s exactly as float64\n&#34;, constant.Real(c)) } Ai, exact := constant.Float64Val(constant.Imag(c)) if !exact { fmt.Printf(&#34;Could not represent imaginary part %s as exactly as float64\n&#34;, constant.Imag(c)) } C := complex(Ar, Ai) fmt.Println(&#34;literal&#34;, 25.3+55i) fmt.Println(&#34;go/constant&#34;, c) fmt.Println(&#34;complex128&#34;, C) } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"> Could not represent real part 25.3 exactly as float64 literal (25.3+55i) go/constant (25.3 + 55i) complex128 (25.299999999999997+55i) </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </section><section class="Documentation-index"> <h3 id="pkg-index" class="Documentation-indexHeader">Index <a href="#pkg-index" aria-label="Go to Index">露</a></h3> <ul class="Documentation-indexList"> <li class="Documentation-indexFunction"> <a href="#BitLen">func BitLen(x Value) int</a></li> <li class="Documentation-indexFunction"> <a href="#BoolVal">func BoolVal(x Value) bool</a></li> <li class="Documentation-indexFunction"> <a href="#Bytes">func Bytes(x Value) []byte</a></li> <li class="Documentation-indexFunction"> <a href="#Compare">func Compare(x_ Value, op token.Token, y_ Value) bool</a></li> <li class="Documentation-indexFunction"> <a href="#Float32Val">func Float32Val(x Value) (float32, bool)</a></li> <li class="Documentation-indexFunction"> <a href="#Float64Val">func Float64Val(x Value) (float64, bool)</a></li> <li class="Documentation-indexFunction"> <a href="#Int64Val">func Int64Val(x Value) (int64, bool)</a></li> <li class="Documentation-indexFunction"> <a href="#Sign">func Sign(x Value) int</a></li> <li class="Documentation-indexFunction"> <a href="#StringVal">func StringVal(x Value) string</a></li> <li class="Documentation-indexFunction"> <a href="#Uint64Val">func Uint64Val(x Value) (uint64, bool)</a></li> <li class="Documentation-indexFunction"> <a href="#Val">func Val(x Value) any</a></li> <li class="Documentation-indexType"> <a href="#Kind">type Kind</a></li> <li><ul class="Documentation-indexTypeMethods"> <li> <a href="#Kind.String">func (i Kind) String() string</a></li> </ul></li> <li class="Documentation-indexType"> <a href="#Value">type Value</a></li> <li><ul class="Documentation-indexTypeFunctions"> <li> <a href="#BinaryOp">func BinaryOp(x_ Value, op token.Token, y_ Value) Value</a></li> <li> <a href="#Denom">func Denom(x Value) Value</a></li> <li> <a href="#Imag">func Imag(x Value) Value</a></li> <li> <a href="#Make">func Make(x any) Value</a></li> <li> <a href="#MakeBool">func MakeBool(b bool) Value</a></li> <li> <a href="#MakeFloat64">func MakeFloat64(x float64) Value</a></li> <li> <a href="#MakeFromBytes">func MakeFromBytes(bytes []byte) Value</a></li> <li> <a href="#MakeFromLiteral">func MakeFromLiteral(lit string, tok token.Token, zero uint) Value</a></li> <li> <a href="#MakeImag">func MakeImag(x Value) Value</a></li> <li> <a href="#MakeInt64">func MakeInt64(x int64) Value</a></li> <li> <a href="#MakeString">func MakeString(s string) Value</a></li> <li> <a href="#MakeUint64">func MakeUint64(x uint64) Value</a></li> <li> <a href="#MakeUnknown">func MakeUnknown() Value</a></li> <li> <a href="#Num">func Num(x Value) Value</a></li> <li> <a href="#Real">func Real(x Value) Value</a></li> <li> <a href="#Shift">func Shift(x Value, op token.Token, s uint) Value</a></li> <li> <a href="#ToComplex">func ToComplex(x Value) Value</a></li> <li> <a href="#ToFloat">func ToFloat(x Value) Value</a></li> <li> <a href="#ToInt">func ToInt(x Value) Value</a></li> <li> <a href="#UnaryOp">func UnaryOp(op token.Token, y Value, prec uint) Value</a></li> </ul></li> </ul> </section><section class="Documentation-examples"> <h4 tabindex="-1" id="pkg-examples" class="Documentation-examplesHeader">Examples <a class="Documentation-idLink" href="#pkg-examples" aria-label="Go to Examples">露</a></h4> <ul class="Documentation-examplesList"> <li><a href="#example-package-ComplexNumbers" class="js-exampleHref">Package (ComplexNumbers)</a></li> <li><a href="#example-BinaryOp" class="js-exampleHref">BinaryOp</a></li> <li><a href="#example-Compare" class="js-exampleHref">Compare</a></li> <li><a href="#example-Sign" class="js-exampleHref">Sign</a></li> <li><a href="#example-UnaryOp" class="js-exampleHref">UnaryOp</a></li> <li><a href="#example-Val" class="js-exampleHref">Val</a></li> </ul> </section><h3 tabindex="-1" id="pkg-constants" class="Documentation-constantsHeader">Constants <a href="#pkg-constants" aria-label="Go to Constants">露</a></h3> <section class="Documentation-constants"><p class="Documentation-empty">This section is empty.</p></section> <h3 tabindex="-1" id="pkg-variables" class="Documentation-variablesHeader">Variables <a href="#pkg-variables" aria-label="Go to Variables">露</a></h3> <section class="Documentation-variables"><p class="Documentation-empty">This section is empty.</p></section> <h3 tabindex="-1" id="pkg-functions" class="Documentation-functionsHeader">Functions <a href="#pkg-functions" aria-label="Go to Functions">露</a></h3> <section class="Documentation-functions"><div class="Documentation-function"> <h4 tabindex="-1" id="BitLen" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=645">BitLen</a> <a class="Documentation-idLink" href="#BitLen" aria-label="Go to BitLen">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func BitLen(x <a href="#Value">Value</a>) <a href="/builtin#int">int</a></pre> </div> <p>BitLen returns the number of bits required to represent the absolute value x in binary representation; x must be an <a href="#Int">Int</a> or an <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, the result is 0. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="BoolVal" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=480">BoolVal</a> <a class="Documentation-idLink" href="#BoolVal" aria-label="Go to BoolVal">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func BoolVal(x <a href="#Value">Value</a>) <a href="/builtin#bool">bool</a></pre> </div> <p>BoolVal returns the Go boolean value of x, which must be a <a href="#Bool">Bool</a> or an <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, the result is false. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Bytes" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=702">Bytes</a> <a class="Documentation-idLink" href="#Bytes" aria-label="Go to Bytes">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Bytes(x <a href="#Value">Value</a>) []<a href="/builtin#byte">byte</a></pre> </div> <p>Bytes returns the bytes for the absolute value of x in little- endian binary representation; x must be an <a href="#Int">Int</a>. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Compare" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=1337">Compare</a> <a class="Documentation-idLink" href="#Compare" aria-label="Go to Compare">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Compare(x_ <a href="#Value">Value</a>, op <a href="/go/token">token</a>.<a href="/go/token#Token">Token</a>, y_ <a href="#Value">Value</a>) <a href="/builtin#bool">bool</a></pre> </div> <p>Compare returns the result of the comparison x op y. The comparison must be defined for the operands. If one of the operands is <a href="#Unknown">Unknown</a>, the result is false. </p> <details tabindex="-1" id="example-Compare" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example <a href="#example-Compare" aria-label="Go to Example">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;go/token&#34; &#34;slices&#34; ) func main() { vs := []constant.Value{ constant.MakeString(&#34;Z&#34;), constant.MakeString(&#34;bacon&#34;), constant.MakeString(&#34;go&#34;), constant.MakeString(&#34;Frame&#34;), constant.MakeString(&#34;defer&#34;), constant.MakeFromLiteral(`&#34;a&#34;`, token.STRING, 0), } slices.SortFunc(vs, func(a, b constant.Value) int { if constant.Compare(a, token.LSS, b) { return -1 } if constant.Compare(a, token.GTR, b) { return +1 } return 0 }) for _, v := range vs { fmt.Println(constant.StringVal(v)) } } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"> Frame Z a bacon defer go </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Float32Val" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=537">Float32Val</a> <a class="Documentation-idLink" href="#Float32Val" aria-label="Go to Float32Val">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Float32Val(x <a href="#Value">Value</a>) (<a href="/builtin#float32">float32</a>, <a href="/builtin#bool">bool</a>)</pre> </div> <p>Float32Val is like <a href="#Float64Val">Float64Val</a> but for float32 instead of float64. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Float64Val" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=562">Float64Val</a> <a class="Documentation-idLink" href="#Float64Val" aria-label="Go to Float64Val">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Float64Val(x <a href="#Value">Value</a>) (<a href="/builtin#float64">float64</a>, <a href="/builtin#bool">bool</a>)</pre> </div> <p>Float64Val returns the nearest Go float64 value of x and whether the result is exact; x must be numeric or an <a href="#Unknown">Unknown</a>, but not <a href="#Complex">Complex</a>. For values too small (too close to 0) to represent as float64, <a href="#Float64Val">Float64Val</a> silently underflows to 0. The result sign always matches the sign of x, even for 0. If x is <a href="#Unknown">Unknown</a>, the result is (0, false). </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Int64Val" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=507">Int64Val</a> <a class="Documentation-idLink" href="#Int64Val" aria-label="Go to Int64Val">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Int64Val(x <a href="#Value">Value</a>) (<a href="/builtin#int64">int64</a>, <a href="/builtin#bool">bool</a>)</pre> </div> <p>Int64Val returns the Go int64 value of x and whether the result is exact; x must be an <a href="#Int">Int</a> or an <a href="#Unknown">Unknown</a>. If the result is not exact, its value is undefined. If x is <a href="#Unknown">Unknown</a>, the result is (0, false). </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Sign" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=665">Sign</a> <a class="Documentation-idLink" href="#Sign" aria-label="Go to Sign">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Sign(x <a href="#Value">Value</a>) <a href="/builtin#int">int</a></pre> </div> <p>Sign returns -1, 0, or 1 depending on whether x &lt; 0, x == 0, or x &gt; 0; x must be numeric or <a href="#Unknown">Unknown</a>. For complex values x, the sign is 0 if x == 0, otherwise it is != 0. If x is <a href="#Unknown">Unknown</a>, the result is 1. </p> <details tabindex="-1" id="example-Sign" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example <a href="#example-Sign" aria-label="Go to Example">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;go/token&#34; ) func main() { zero := constant.MakeInt64(0) one := constant.MakeInt64(1) negOne := constant.MakeInt64(-1) mkComplex := func(a, b constant.Value) constant.Value { b = constant.MakeImag(b) return constant.BinaryOp(a, token.ADD, b) } vs := []constant.Value{ negOne, mkComplex(zero, negOne), mkComplex(one, negOne), mkComplex(negOne, one), mkComplex(negOne, negOne), zero, mkComplex(zero, zero), one, mkComplex(zero, one), mkComplex(one, one), } for _, v := range vs { fmt.Printf(&#34;% d %s\n&#34;, constant.Sign(v), v) } } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"> -1 -1 -1 (0 + -1i) -1 (1 + -1i) -1 (-1 + 1i) -1 (-1 + -1i) 0 0 0 (0 + 0i) 1 1 1 (0 + 1i) 1 (1 + 1i) </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div><div class="Documentation-function"> <h4 tabindex="-1" id="StringVal" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=493">StringVal</a> <a class="Documentation-idLink" href="#StringVal" aria-label="Go to StringVal">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func StringVal(x <a href="#Value">Value</a>) <a href="/builtin#string">string</a></pre> </div> <p>StringVal returns the Go string value of x, which must be a <a href="#String">String</a> or an <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, the result is &#34;&#34;. </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Uint64Val" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=523">Uint64Val</a> <a class="Documentation-idLink" href="#Uint64Val" aria-label="Go to Uint64Val">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Uint64Val(x <a href="#Value">Value</a>) (<a href="/builtin#uint64">uint64</a>, <a href="/builtin#bool">bool</a>)</pre> </div> <p>Uint64Val returns the Go uint64 value of x and whether the result is exact; x must be an <a href="#Int">Int</a> or an <a href="#Unknown">Unknown</a>. If the result is not exact, its value is undefined. If x is <a href="#Unknown">Unknown</a>, the result is (0, false). </p> </div><div class="Documentation-function"> <h4 tabindex="-1" id="Val" data-kind="function" class="Documentation-functionHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=593">Val</a> <a class="Documentation-idLink" href="#Val" aria-label="Go to Val">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.13</span> </span> </h4> <div class="Documentation-declaration"> <pre>func Val(x <a href="#Value">Value</a>) <a href="/builtin#any">any</a></pre> </div> <p>Val returns the underlying value for a given constant. Since it returns an interface, it is up to the caller to type assert the result to the expected type. The possible dynamic return types are: </p><pre>x Kind type of result ----------------------------------------- Bool bool String string Int int64 or *big.Int Float *big.Float or *big.Rat everything else nil </pre> <details tabindex="-1" id="example-Val" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example <a href="#example-Val" aria-label="Go to Example">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;math&#34; ) func main() { maxint := constant.MakeInt64(math.MaxInt64) fmt.Printf(&#34;%v\n&#34;, constant.Val(maxint)) e := constant.MakeFloat64(math.E) fmt.Printf(&#34;%v\n&#34;, constant.Val(e)) b := constant.MakeBool(true) fmt.Printf(&#34;%v\n&#34;, constant.Val(b)) b = constant.Make(false) fmt.Printf(&#34;%v\n&#34;, constant.Val(b)) } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"> 9223372036854775807 6121026514868073/2251799813685248 true false </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div></section> <h3 tabindex="-1" id="pkg-types" class="Documentation-typesHeader">Types <a href="#pkg-types" aria-label="Go to Types">露</a></h3> <section class="Documentation-types"><div class="Documentation-type"> <h4 tabindex="-1" id="Kind" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=29">Kind</a> <a class="Documentation-idLink" href="#Kind" aria-label="Go to Kind">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type Kind <a href="/builtin#int">int</a></pre> </div> <p>Kind specifies the kind of value represented by a <a href="#Value">Value</a>. </p> <div class="Documentation-typeConstant"> <div class="Documentation-declaration"> <pre>const ( <span id="Unknown" data-kind="constant"> <span class="comment">// unknown values</span> </span> Unknown <a href="#Kind">Kind</a> = <a href="/builtin#iota">iota</a> <span class="comment">// non-numeric values</span> <span id="Bool" data-kind="constant"> Bool </span><span id="String" data-kind="constant"> String </span> <span class="comment">// numeric values</span> <span id="Int" data-kind="constant"> Int </span><span id="Float" data-kind="constant"> Float </span><span id="Complex" data-kind="constant"> Complex </span>)</pre> </div> </div><div class="Documentation-typeMethod"> <h4 tabindex="-1" id="Kind.String" data-kind="method" class="Documentation-typeMethodHeader"> <span>func (Kind) <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/kind_string.go;l=23">String</a> <a class="Documentation-idLink" href="#Kind.String" aria-label="Go to Kind.String">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.18</span> </span> </h4> <div class="Documentation-declaration"> <pre>func (i <a href="#Kind">Kind</a>) String() <a href="/builtin#string">string</a></pre> </div> </div> </div><div class="Documentation-type"> <h4 tabindex="-1" id="Value" data-kind="type" class="Documentation-typeHeader"> <span>type <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=46">Value</a> <a class="Documentation-idLink" href="#Value" aria-label="Go to Value">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>type Value interface { <span id="Value.Kind" data-kind="method"> <span class="comment">// Kind returns the value kind.</span> </span> Kind() <a href="#Kind">Kind</a> <span id="Value.String" data-kind="method"> <span class="comment">// String returns a short, quoted (human-readable) form of the value.</span> </span> <span class="comment">// For numeric values, the result may be an approximation;</span> <span class="comment">// for String values the result may be a shortened string.</span> <span class="comment">// Use ExactString for a string representing a value exactly.</span> String() <a href="/builtin#string">string</a> <span id="Value.ExactString" data-kind="method"> <span class="comment">// ExactString returns an exact, quoted (human-readable) form of the value.</span> </span> <span class="comment">// If the Value is of Kind String, use StringVal to obtain the unquoted string.</span> ExactString() <a href="/builtin#string">string</a> <span class="comment">// contains filtered or unexported methods</span> }</pre> </div> <p>A Value represents the value of a Go constant. </p> <div class="Documentation-typeFunc"> <h4 tabindex="-1" id="BinaryOp" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=1103">BinaryOp</a> <a class="Documentation-idLink" href="#BinaryOp" aria-label="Go to BinaryOp">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func BinaryOp(x_ <a href="#Value">Value</a>, op <a href="/go/token">token</a>.<a href="/go/token#Token">Token</a>, y_ <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>BinaryOp returns the result of the binary expression x op y. The operation must be defined for the operands. If one of the operands is <a href="#Unknown">Unknown</a>, the result is <a href="#Unknown">Unknown</a>. BinaryOp doesn&#39;t handle comparisons or shifts; use <a href="#Compare">Compare</a> or <a href="#Shift">Shift</a> instead. </p><p>To force integer division of <a href="#Int">Int</a> operands, use op == <a href="/go/token#QUO_ASSIGN">token.QUO_ASSIGN</a> instead of <a href="/go/token#QUO">token.QUO</a>; the result is guaranteed to be <a href="#Int">Int</a> in this case. Division by zero leads to a run-time panic. </p> <details tabindex="-1" id="example-BinaryOp" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example <a href="#example-BinaryOp" aria-label="Go to Example">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;go/token&#34; ) func main() { // 11 / 0.5 a := constant.MakeUint64(11) b := constant.MakeFloat64(0.5) c := constant.BinaryOp(a, token.QUO, b) fmt.Println(c) } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput">22 </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Denom" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=788">Denom</a> <a class="Documentation-idLink" href="#Denom" aria-label="Go to Denom">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Denom(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>Denom returns the denominator of x; x must be <a href="#Int">Int</a>, <a href="#Float">Float</a>, or <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, or if it is too large or small to represent as a fraction, the result is <a href="#Unknown">Unknown</a>. Otherwise the result is an <a href="#Int">Int</a> &gt;= 1. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Imag" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=836">Imag</a> <a class="Documentation-idLink" href="#Imag" aria-label="Go to Imag">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Imag(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>Imag returns the imaginary part of x, which must be a numeric or unknown value. If x is <a href="#Unknown">Unknown</a>, the result is <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Make" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=623">Make</a> <a class="Documentation-idLink" href="#Make" aria-label="Go to Make">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.13</span> </span> </h4> <div class="Documentation-declaration"> <pre>func Make(x <a href="/builtin#any">any</a>) <a href="#Value">Value</a></pre> </div> <p>Make returns the <a href="#Value">Value</a> for x. </p><pre>type of x result Kind ---------------------------- bool Bool string String int64 Int *big.Int Int *big.Float Float *big.Rat Float anything else Unknown </pre> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeBool" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=386">MakeBool</a> <a class="Documentation-idLink" href="#MakeBool" aria-label="Go to MakeBool">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeBool(b <a href="/builtin#bool">bool</a>) <a href="#Value">Value</a></pre> </div> <p>MakeBool returns the <a href="#Bool">Bool</a> value for b. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeFloat64" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=412">MakeFloat64</a> <a class="Documentation-idLink" href="#MakeFloat64" aria-label="Go to MakeFloat64">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeFloat64(x <a href="/builtin#float64">float64</a>) <a href="#Value">Value</a></pre> </div> <p>MakeFloat64 returns the <a href="#Float">Float</a> value for x. If x is -0.0, the result is 0.0. If x is not finite, the result is an <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeFromBytes" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=734">MakeFromBytes</a> <a class="Documentation-idLink" href="#MakeFromBytes" aria-label="Go to MakeFromBytes">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeFromBytes(bytes []<a href="/builtin#byte">byte</a>) <a href="#Value">Value</a></pre> </div> <p>MakeFromBytes returns the <a href="#Int">Int</a> value given the bytes of its little-endian binary representation. An empty byte slice argument represents 0. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeFromLiteral" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=427">MakeFromLiteral</a> <a class="Documentation-idLink" href="#MakeFromLiteral" aria-label="Go to MakeFromLiteral">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeFromLiteral(lit <a href="/builtin#string">string</a>, tok <a href="/go/token">token</a>.<a href="/go/token#Token">Token</a>, zero <a href="/builtin#uint">uint</a>) <a href="#Value">Value</a></pre> </div> <p>MakeFromLiteral returns the corresponding integer, floating-point, imaginary, character, or string value for a Go literal string. The tok value must be one of <a href="/go/token#INT">token.INT</a>, <a href="/go/token#FLOAT">token.FLOAT</a>, <a href="/go/token#IMAG">token.IMAG</a>, <a href="/go/token#CHAR">token.CHAR</a>, or <a href="/go/token#STRING">token.STRING</a>. The final argument must be zero. If the literal string syntax is invalid, the result is an <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeImag" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=810">MakeImag</a> <a class="Documentation-idLink" href="#MakeImag" aria-label="Go to MakeImag">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeImag(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>MakeImag returns the <a href="#Complex">Complex</a> value x*i; x must be <a href="#Int">Int</a>, <a href="#Float">Float</a>, or <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, the result is <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeInt64" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=399">MakeInt64</a> <a class="Documentation-idLink" href="#MakeInt64" aria-label="Go to MakeInt64">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeInt64(x <a href="/builtin#int64">int64</a>) <a href="#Value">Value</a></pre> </div> <p>MakeInt64 returns the <a href="#Int">Int</a> value for x. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeString" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=389">MakeString</a> <a class="Documentation-idLink" href="#MakeString" aria-label="Go to MakeString">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeString(s <a href="/builtin#string">string</a>) <a href="#Value">Value</a></pre> </div> <p>MakeString returns the <a href="#String">String</a> value for s. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeUint64" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=402">MakeUint64</a> <a class="Documentation-idLink" href="#MakeUint64" aria-label="Go to MakeUint64">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeUint64(x <a href="/builtin#uint64">uint64</a>) <a href="#Value">Value</a></pre> </div> <p>MakeUint64 returns the <a href="#Int">Int</a> value for x. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="MakeUnknown" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=383">MakeUnknown</a> <a class="Documentation-idLink" href="#MakeUnknown" aria-label="Go to MakeUnknown">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func MakeUnknown() <a href="#Value">Value</a></pre> </div> <p>MakeUnknown returns the <a href="#Unknown">Unknown</a> value. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Num" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=766">Num</a> <a class="Documentation-idLink" href="#Num" aria-label="Go to Num">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Num(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>Num returns the numerator of x; x must be <a href="#Int">Int</a>, <a href="#Float">Float</a>, or <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, or if it is too large or small to represent as a fraction, the result is <a href="#Unknown">Unknown</a>. Otherwise the result is an <a href="#Int">Int</a> with the same sign as x. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Real" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=823">Real</a> <a class="Documentation-idLink" href="#Real" aria-label="Go to Real">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Real(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>Real returns the real part of x, which must be a numeric or unknown value. If x is <a href="#Unknown">Unknown</a>, the result is <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="Shift" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=1282">Shift</a> <a class="Documentation-idLink" href="#Shift" aria-label="Go to Shift">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func Shift(x <a href="#Value">Value</a>, op <a href="/go/token">token</a>.<a href="/go/token#Token">Token</a>, s <a href="/builtin#uint">uint</a>) <a href="#Value">Value</a></pre> </div> <p>Shift returns the result of the shift expression x op s with op == <a href="/go/token#SHL">token.SHL</a> or <a href="/go/token#SHR">token.SHR</a> (&lt;&lt; or &gt;&gt;). x must be an <a href="#Int">Int</a> or an <a href="#Unknown">Unknown</a>. If x is <a href="#Unknown">Unknown</a>, the result is x. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="ToComplex" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=929">ToComplex</a> <a class="Documentation-idLink" href="#ToComplex" aria-label="Go to ToComplex">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.6</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ToComplex(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>ToComplex converts x to a <a href="#Complex">Complex</a> value if x is representable as a <a href="#Complex">Complex</a>. Otherwise it returns an <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="ToFloat" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=908">ToFloat</a> <a class="Documentation-idLink" href="#ToFloat" aria-label="Go to ToFloat">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.6</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ToFloat(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>ToFloat converts x to a <a href="#Float">Float</a> value if x is representable as a <a href="#Float">Float</a>. Otherwise it returns an <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="ToInt" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=854">ToInt</a> <a class="Documentation-idLink" href="#ToInt" aria-label="Go to ToInt">露</a></span> <span class="Documentation-sinceVersion"> <span class="Documentation-sinceVersionLabel">added in</span> <span class="Documentation-sinceVersionVersion">go1.6</span> </span> </h4> <div class="Documentation-declaration"> <pre>func ToInt(x <a href="#Value">Value</a>) <a href="#Value">Value</a></pre> </div> <p>ToInt converts x to an <a href="#Int">Int</a> value if x is representable as an <a href="#Int">Int</a>. Otherwise it returns an <a href="#Unknown">Unknown</a>. </p> </div><div class="Documentation-typeFunc"> <h4 tabindex="-1" id="UnaryOp" data-kind="function" class="Documentation-typeFuncHeader"> <span>func <a class="Documentation-source" href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go;l=958">UnaryOp</a> <a class="Documentation-idLink" href="#UnaryOp" aria-label="Go to UnaryOp">露</a></span> <span class="Documentation-sinceVersion"> </span> </h4> <div class="Documentation-declaration"> <pre>func UnaryOp(op <a href="/go/token">token</a>.<a href="/go/token#Token">Token</a>, y <a href="#Value">Value</a>, prec <a href="/builtin#uint">uint</a>) <a href="#Value">Value</a></pre> </div> <p>UnaryOp returns the result of the unary expression op y. The operation must be defined for the operand. If prec &gt; 0 it specifies the ^ (xor) result size in bits. If y is <a href="#Unknown">Unknown</a>, the result is <a href="#Unknown">Unknown</a>. </p> <details tabindex="-1" id="example-UnaryOp" class="Documentation-exampleDetails js-exampleContainer"> <summary class="Documentation-exampleDetailsHeader">Example <a href="#example-UnaryOp" aria-label="Go to Example">露</a></summary> <div class="Documentation-exampleDetailsBody"> <pre class="Documentation-exampleCode"> package main import ( &#34;fmt&#34; &#34;go/constant&#34; &#34;go/token&#34; ) func main() { vs := []constant.Value{ constant.MakeBool(true), constant.MakeFloat64(2.7), constant.MakeUint64(42), } for i, v := range vs { switch v.Kind() { case constant.Bool: vs[i] = constant.UnaryOp(token.NOT, v, 0) case constant.Float: vs[i] = constant.UnaryOp(token.SUB, v, 0) case constant.Int: // Use 16-bit precision. // This would be equivalent to ^uint16(v). vs[i] = constant.UnaryOp(token.XOR, v, 16) } } for _, v := range vs { fmt.Println(v) } } </pre> <pre><span class="Documentation-exampleOutputLabel">Output:</span> <span class="Documentation-exampleOutput"> false -2.7 65493 </span></pre> </div> <div class="Documentation-exampleButtonsContainer"> <p class="Documentation-exampleError" role="alert" aria-atomic="true"></p> <button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button> <button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button> <button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button> </div></details> </div> </div></section></div> </div> </div> <div class="UnitFiles js-unitFiles"> <h2 class="UnitFiles-title" id="section-sourcefiles"> <img class="go-Icon" height="24" width="24" src="/static/shared/icon/insert_drive_file_gm_grey_24dp.svg" alt=""> Source Files <a class="UnitFiles-idLink" href="#section-sourcefiles" aria-label="Go to Source Files">露</a> </h2> <div class="UnitFiles-titleLink"> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant" target="_blank" rel="noopener">View all Source files</a> </div> <div> <ul class="UnitFiles-fileList"><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/kind_string.go" target="_blank" rel="noopener" title="kind_string.go">kind_string.go</a> </li><li> <a href="https://cs.opensource.google/go/go/+/go1.23.3:src/go/constant/value.go" target="_blank" rel="noopener" title="value.go">value.go</a> </li></ul> </div> </div> </div> </div> <div id="showInternal-description" hidden> Click to show internal directories. </div> <div id="hideInternal-description" hidden> Click to hide internal directories. </div> </article> <footer class="go-Main-footer"></footer> </main> <footer class="go-Footer"> <div class="go-Footer-links"> <div class="go-Footer-linkColumn"> <a href="https://go.dev/solutions" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Why Go </a> <a href="https://go.dev/solutions#use-cases" class="go-Footer-link" data-gtmc="footer link"> Use Cases </a> <a href="https://go.dev/solutions#case-studies" class="go-Footer-link" data-gtmc="footer link"> Case Studies </a> </div> <div class="go-Footer-linkColumn"> <a href="https://learn.go.dev/" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Get Started </a> <a href="https://play.golang.org" class="go-Footer-link" data-gtmc="footer link"> Playground </a> <a href="https://tour.golang.org" class="go-Footer-link" data-gtmc="footer link"> Tour </a> <a href="https://stackoverflow.com/questions/tagged/go?tab=Newest" class="go-Footer-link" data-gtmc="footer link"> Stack Overflow </a> <a href="https://go.dev/help" class="go-Footer-link" data-gtmc="footer link"> Help </a> </div> <div class="go-Footer-linkColumn"> <a href="https://pkg.go.dev" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Packages </a> <a href="/std" class="go-Footer-link" data-gtmc="footer link"> Standard Library </a> <a href="/golang.org/x" class="go-Footer-link" data-gtmc="footer link"> Sub-repositories </a> <a href="https://pkg.go.dev/about" class="go-Footer-link" data-gtmc="footer link"> About Go Packages </a> </div> <div class="go-Footer-linkColumn"> <a href="https://go.dev/project" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> About </a> <a href="https://go.dev/dl/" class="go-Footer-link" data-gtmc="footer link">Download</a> <a href="https://go.dev/blog" class="go-Footer-link" data-gtmc="footer link">Blog</a> <a href="https://github.com/golang/go/issues" class="go-Footer-link" data-gtmc="footer link"> Issue Tracker </a> <a href="https://go.dev/doc/devel/release.html" class="go-Footer-link" data-gtmc="footer link"> Release Notes </a> <a href="https://blog.golang.org/go-brand" class="go-Footer-link" data-gtmc="footer link"> Brand Guidelines </a> <a href="https://go.dev/conduct" class="go-Footer-link" data-gtmc="footer link"> Code of Conduct </a> </div> <div class="go-Footer-linkColumn"> <a href="https://www.twitter.com/golang" class="go-Footer-link go-Footer-link--primary" data-gtmc="footer link"> Connect </a> <a href="https://www.twitter.com/golang" class="go-Footer-link" data-gtmc="footer link"> Twitter </a> <a href="https://github.com/golang" class="go-Footer-link" data-gtmc="footer link">GitHub</a> <a href="https://invite.slack.golangbridge.org/" class="go-Footer-link" data-gtmc="footer link"> Slack </a> <a href="https://reddit.com/r/golang" class="go-Footer-link" data-gtmc="footer link"> r/golang </a> <a href="https://www.meetup.com/pro/go" class="go-Footer-link" data-gtmc="footer link"> Meetup </a> <a href="https://golangweekly.com/" class="go-Footer-link" data-gtmc="footer link"> Golang Weekly </a> </div> </div> <div class="go-Footer-bottom"> <img class="go-Footer-gopher" width="1431" height="901" src="/static/shared/gopher/pilot-bust-1431x901.svg" alt="Gopher in flight goggles"> <ul class="go-Footer-listRow"> <li class="go-Footer-listItem"> <a href="https://go.dev/copyright" data-gtmc="footer link">Copyright</a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/tos" data-gtmc="footer link">Terms of Service</a> </li> <li class="go-Footer-listItem"> <a href="http://www.google.com/intl/en/policies/privacy/" data-gtmc="footer link" target="_blank" rel="noopener"> Privacy Policy </a> </li> <li class="go-Footer-listItem"> <a href="https://go.dev/s/pkgsite-feedback" target="_blank" rel="noopener" data-gtmc="footer link"> Report an Issue </a> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-toggleTheme js-toggleTheme" aria-label="Theme Toggle"> <img data-value="auto" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_6_gm_grey_24dp.svg" alt="System theme"> <img data-value="dark" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/brightness_2_gm_grey_24dp.svg" alt="Dark theme"> <img data-value="light" class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/light_mode_gm_grey_24dp.svg" alt="Light theme"> <p> Theme Toggle </p> </button> </li> <li class="go-Footer-listItem"> <button class="go-Button go-Button--text go-Footer-keyboard js-openShortcuts" aria-label="Shorcuts Modal"> <img class="go-Icon go-Icon--inverted" height="24" width="24" src="/static/shared/icon/keyboard_grey_24dp.svg" alt=""> <p> Shortcuts Modal </p> </button> </li> </ul> <a class="go-Footer-googleLogo" href="https://google.com" target="_blank"rel="noopener" data-gtmc="footer link"> <img class="go-Footer-googleLogoImg" height="24" width="72" src="/static/shared/logo/google-white.svg" alt="Google logo"> </a> </div> </footer> <dialog id="jump-to-modal" class="JumpDialog go-Modal go-Modal--md js-modal"> <form method="dialog" data-gmtc="jump to form" aria-label="Jump to Identifier"> <div class="Dialog-title go-Modal-header"> <h2>Jump to</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="JumpDialog-filter"> <input class="JumpDialog-input go-Input" autocomplete="off" type="text"> </div> <div class="JumpDialog-body go-Modal-body"> <div class="JumpDialog-list"></div> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <dialog class="ShortcutsDialog go-Modal go-Modal--sm js-modal"> <form method="dialog"> <div class="go-Modal-header"> <h2>Keyboard shortcuts</h2> <button class="go-Button go-Button--inline" type="button" data-modal-close data-gtmc="modal button" aria-label="Close" > <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="" /> </button> </div> <div class="go-Modal-body"> <table> <tbody> <tr><td class="ShortcutsDialog-key"> <strong>?</strong></td><td> : This menu</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>/</strong></td><td> : Search site</td> </tr> <tr><td class="ShortcutsDialog-key"> <strong>f</strong> or <strong>F</strong></td><td> : Jump to</td> </tr> <tr> <td class="ShortcutsDialog-key"><strong>y</strong> or <strong>Y</strong></td> <td> : Canonical URL</td> </tr> </tbody> </table> </div> <div class="go-Modal-actions"> <button class="go-Button" data-test-id="close-dialog">Close</button> </div> </form> </dialog> <section class="Cookie-notice js-cookieNotice"> <div>go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a target=_blank href="https://policies.google.com/technologies/cookies">Learn more.</a></div> <div><button class="go-Button">Okay</button></div> </section> <script> // this will throw if the querySelector can鈥檛 find the element const gtmId = document.querySelector('.js-gtmID').dataset.gtmid; if (!gtmId) { throw new Error('Google Tag Manager ID not found'); } loadScript(`https://www.googletagmanager.com/gtm.js?id=${gtmId}`); </script> <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W8MVQXG" height="0" width="0" style="display:none;visibility:hidden"> </iframe> </noscript> <div class="js-canonicalURLPath" data-canonical-url-path="/go/constant@go1.23.3" hidden></div> <div class="js-playgroundVars" data-modulepath="std" data-version="v1.23.3" hidden></div> <script> loadScript('/static/frontend/unit/main/main.js') </script> <script> loadScript('/static/frontend/unit/unit.js') </script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10