Go 1.13 Modernizes Number Literals
Written by Kay Ewbank   
Thursday, 05 September 2019

The latest six-monthly update to Go has been released with a more uniform and modernized set of number literal prefixes.

Go is an open source project developed by a team at Google and many contributors from the open source community over more than 8 years. The main intended use is as a systems programming language, and it has been used in high profile commercial successes such as Docker.

goblack 1 

Alongside Go 1.13, the Go development team has also announced the availability of a number of services run by Google, including a module mirror for accelerating Go module downloads, an index for discovering new modules, and a global go.sum database for authenticating module content.

The thinking behind the change to the number literal prefixes comes from the fact that while the Go development team adopted C’s number literal syntax when it was initially designed, it hasn't kept up with the changes to the 'C-numbered languages'. Other languages such as C, C++, C#, Java, JavaScript, PHP and Python have extended their number literals to add some or all of binary, octal and hexadecimal integer literals. Go has now added all these, which the development team says should make it easier for developers to move between Go and the other C-numbered languages.

Go programmers can now specify literals using the following prefixes:

  • Binary integer literals: The prefix 0b or 0B indicates a binary integer literal such as 0b1011.
  • Octal integer literals: The prefix 0o or 0O indicates an octal integer literal such as 0o660. The existing octal notation indicated by a leading 0 followed by octal digits remains valid.
  • Hexadecimal floating point literals: The prefix 0x or 0X may now be used to express the mantissa of a floating-point number in hexadecimal format such as 0x1.0p-1021. A hexadecimal floating-point number must always have an exponent, written as the letter p or P followed by an exponent in decimal. The exponent scales the mantissa by 2 to the power of the exponent.
  • Imaginary literals: The imaginary suffix i may now be used with any (binary, decimal, hexadecimal) integer or floating-point literal.
  • Digit separators: The digits of any number literal may now be separated (grouped) using underscores, such as in 1_000_000, 0b_1010_0110, or 3.1415_9265. An underscore may appear between any two digits or the literal prefix and the first digit.

The language changes were implemented by changes to the compiler, and corresponding internal changes to the library packages.  

goblack 1

More Information

GoLang Home Page

Related Articles

Go Rejects The Syntactic Sugar Of Try

Go Survey Shows Show Continuing Preference For Go

Go Survey Revelations

Go Developer Network Launched

Go 2 Details Revealed

Help Go Develop

Go 1.11 Adds WebAssembly Port

Go 1.10 Adds Automatic Caching

A Programmer's Guide To Go With Visual Studio Code

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Wasmer 5 Adds iOS Support
12/11/2024

The Wasmer team has released Wasmer 5.0. The WebAssembly runtime adds experimental support for more back ends including V8, Wasmi and WAMR. It also now has iOS support, and upgraded compilers includin [ ... ]



Pico 2W Announced But There Is A Surprise!
25/11/2024

Raspberry Pi released the Pico 2 a few months ago and we have been waiting for the Pico 2W since then. But Pimoroni beat them to the draw with the Pico Plus 2W based on the RM2 radio module and hinted [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 05 September 2019 )