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


Ursina - A Game Engine Powered by Python
08/11/2024

Ursina is a new open source game engine in which you can code any type of game in Python, be it 2-D, 3-D, an application, a visualization, you name it.



AI Propels Python To Top Language on GitHub
30/10/2024

This year's Octoverse Report reveals how AI is expanding on GitHub and that Python has now overtaken JavaScript as the most popular language on GitHub. The use of Jupyter Notebooks has also surged.


More News

espbook

 

Comments




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

Last Updated ( Thursday, 05 September 2019 )