Nice. I first saw this in Rust, and it seemed like such an obviously good idea (allowing underscores in numeric literals) that I've wondered why more languages don't do it. Now I'm curious where it originated.
Nice. I first saw this in Rust, and it seemed like such an obviously good idea (allowing underscores in numeric literals) that I've wondered why more languages don't do it. Now I'm curious where it originated.
I would like to see a universal format agreed on by everyone, so that numbers with separators (call them punctuated numbers) output by one program could be used as input for another, as is often done in Unix pipelines.
The languages that I know of that have punctuated numbers all use underscores. However, having thought about it a lot, I don't think this is a good choice. First, the underscore is often used, as in C, as an additional character in identifiers, but the semantics are different. An underscore in an identifier is significant, in a number it is not:
1_234_567 == 1234567, but
my_long_identifier != mylongidentifier
Also, the underscore is too "big". In a fixed width font, this is irrelevant, but in a variable width font, I think it makes numbers look ugly. The separator should be narrow. In some locales, the apostrophe is used:
1'234'567
I like the thinner character. I have at least one calculator that uses this convention in the display. Alas, this is probably unworkable in computers, since the apostrophe is used commonly for quoting. One option that might work is the back quote:
1`234`567
The back quote isn't used as much as the apostrophe, but it still might cause problems. On US keyboards, it's conveniently located right next to the 1.
Finally, I'd like to see both period and comma accepted as the decimal separator
1`234`567.89 == 1`234`567,89
but there are some obvious problems with that.
My bottom line is that, before C++, or any other language, adds underscores as thousands separators because that's what everyone else did, we should think more deeply about what's needed in a universal format for punctuated numbers.
Unfortunately it doesn’t work in languages without some redundancy, like many in the vector family. Is this a four-vector of one-digit numbers or a one-vector of a four-digit number?
[1 2 3 4] int i = BOOST_BINARY( 1 0010 0010 0000 1000 );(Incidentally, one of the perils of trying to draw historical conclusions from text searches, or data sets like Google Ngrams: you could get completely wrong results if you miss a shift in spelling or word usage.)
http://docs.oracle.com/javase/7/docs/technotes/guides/langua...