4 ms·
C++17: > Single-quotation-mark as a digit separator I have to admit to utter befuddlement about why you would ever want that. (Presumably they will also requi
by kabdib 11y ago
C++17:
> Single-quotation-mark as a digit separator
I have to admit to utter befuddlement about why you would ever want that. (Presumably they will also require scanf to honor this as well . . . that'll be fun).
Just when I thought the C++ committees were getting their heads screwed on straight. Am I missing something, or is this another trigraph disaster?
- theseoafs 11y agoWhat number is this? 100000000000000
- gamegoblin 11y agoI actually really like the Java way of doing this: 100_000_000_000_000
- JoachimSchipper 11y agoThat works, but even in C I'd simply write this as (100 * 1000 * 1000 * 1000 * 1000), which is perfectly clear and no slower. (Or, rather, as ((uint64_t)100 * 1000 * 1000 * 1000 * 1000), but you'll need to do something to prevent overflow in most languages, anyway.)
- tzs 11y agoThat also works in Perl, Ruby, C#, ADA, D, and Julia. According to Wikipedia [1] underscore was proposed for C++ but rejected because it conflicts with user-defined literals. Is there any reason they could not have used space? Offhand, I can't think of anyplace where a space in a literal number would not currently be illegal, so adding that as a separator should not introduce any problems, but C++ has grown massively in complexity since I last seriously used it so I could easily have overlooked something. [1] https://en.m.wikipedia.org/wiki/Integer_literal#Digit_separators https://en.m.wikipedia.org/wiki/Integer_literal#Digit_separa...
- pklausler 11y agoA space could not be allowed in numeric values in runtime input (fscanf, <<).
- rootbear 11y agoI actually like this, and had decided that single quotes were a good digit separator even before C++ adopted it. I had a calculator, an HP, I think, that used single quotes as digit separators in the LCD display. There is actually a locale that uses single quotes: de_CH, the Swiss High German locale. There are no locales that use underscore as far as I know. I have a few aliases like this: alias dfk='LC_NUMERIC=de_CH df --block-size=\'\''1024' alias duk='LC_NUMERIC=de_CH du --block-size=\'\''1024' that help me when something like du -h won't do. Also, the underscore is used to separate words in variable names, where it is significant. int my_long_var_name, mylongvarname; are different variables. But in numeric constants, the underscore has no meaning. 186_282.397 and 186282.397 would be the same number. This is inconsistent. Finally, in a variable width font, the single quote is much less visually intrusive than the underscore, which tends to be a wide character. I would like to see this form used universally. In my wildest fantasies, I'd also allow either '.' or ',' as the decimal indicator. That would make some of my European friends happy.