4

Coding in Julia shows that using underscore as integer digit separator works in Julia.

x = 1_000_000

and

   x = 1000000

are basically the same thing.

However, I am not able to locate the documentation for this, to read more details. Could anyone point me to that.

Also is digit separation character a common thing in different languages? What are the separator character in C++, java, and Python?

user25004
  • 1,868
  • 1
  • 22
  • 47

2 Answers2

6

The standards proposal document for C++14 has a very lengthy discussion on the rationale and possible choices for a digit separator. The considered `, ', _, ::, and (space). Some of the discussion cites other languages. According to the document, _ is also used in Ada, VHDL, Verilog, and possibly Algol68. Underscores also appear to be used in Java 7 (StackOverflow question, proposal). C++ settled on ' as their separator.

Julia hasn't formally documented underscore-separated numeric literals yet, but you can find some information in this GitHub issue (#848) and this julia-dev thread.

It doesn't look like Python has a numeric literal separator.

Community
  • 1
  • 1
mbauman
  • 30,958
  • 4
  • 88
  • 123
  • 3
    `_` is also used in [Perl](http://perldoc.perl.org/perldata.html#Scalar-value-constructors). – Vincent Zoonekynd Jul 22 '15 at 00:21
  • 1
    Note: Algol68 sidestepped the entire issue by allowing a space in a number, for example: 1 million could be 1 000 000, and π could be 3.14159 26535 89793 23846 ... – NevilleDNZ Sep 19 '15 at 23:40
3

I've just made a pull request to add this to the manual, when you spot things missing it's very easy to add them to the documentation, see:

HarmonicaMuse
  • 7,633
  • 37
  • 52