Paul Krill
Editor at Large

Golang 1.13 adds number literal prefixes

news
Sep 4, 20192 mins

Go language extensions should make it easier for programmers to move between Go and other C-family languages

Glowing abstract numbers
Credit: Thinkstock

Go (Golang) 1.13, the latest version of Google’s open source language, is now available as a production release. The update supports a more uniform and modernized set of number literal prefixes.

Go 1.13 was released on September 3 after beta and release candidate stages spanning from late June through August. Language changes in the release abide by the golang number literal proposal, which extends the language to make it easier for developers to move between Go and other “C-numbered” languages including C, C++, C#, Java, and JavaScript. 

Go adopted C’s number literal syntax from the beginning, but while most other C-numbered languages have added binary integer literals, alternate octal integer literals, hexadecimal floating point literals, and support for _ as a digit separator in number literals, Go has not kept up with these extensions—until now.

Language changes in Go 1.13, which arrived about six months after Go 1.12, include:

  • For binary integer literals, the prefix 0b or 0B indicates a binary integer literal such as Ob1011.
  • For hexadecimal floating point literals, the prefix 0x or 0X can express the mantissa of a floating point number in hexadecimal format such as 0x1.op-1021. A hexadecimal floating point has to have an exponent, written as the letter p or P followed by an exponent in decimal. The exponent scales the mantissa by two to the power of the exponent.
  • For octal integer literals, the prefix 0o indicates an octal integer literal such as 0o660. The existing octal notation, which leads with 0 followed by octal digits, is still valid.
  • The imaginary suffix, i, now may be used with any binary, decimal, or hexadecimal integer or floating point literal.
  • Digits of any number literal now can be separated using underscores. An underscore ( _ ) may appear between any two digits or the literal prefix and the first digit.

Language changes were implemented by changes to the compiler and corresponding changes to library packages. Go 1.13 also removes the restriction that a shift count has to be signed, eliminating the need for many artificial uint conversions. The compiler, meanwhile, has a more precise implementation of escape analysis. Also, TLS (Transport Layer Security) 1.3 is enabled in the crypto/tls package by default.

You can download Go 1.13 from golang.org. 

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author