Less free underscores in number literals

Olivier Pisano olivier.pisano at laposte.net
Sat Oct 23 03:00:41 PDT 2010


Le 23/10/2010 05:11, bearophile a écrit :
> This is a minor thing, if you aren't interested, ignore it.
>
> The support for underscore in number literals as done in D and Ada is a feature I like a lot. But you may write:
>
> long x = 1_000_000_000_00;
>
> The usage of underscores there doesn't correspond to the thousands, this may lead to mistakes, and then maybe to bugs. Something similar may happen for hex (both integral and FP), octal or binary number literals (that usually you don't divide in groups of 3).
>
> In D I have written numbers with underscores positioned in a way that I consider wrong.
>
> So isn't it better to restrict the usage of the underscores every 3 digits (starting from the less significant one) for decimal literals, and every 4 or 8 or 16 or 32 digits in binary/octal/hex number literals? (4 or 8 or 16 or 32 means that you are free to use one of those four styles, but then you need to use it consistently in one number literal).
>
> A problem with this is that not everybody uses groups of 3 digits in decimal number literals (Do Chinese people use groups of four?).
>
> (When I have proposed to introduce underscores in Python number literals they have discussed about this sub topic too.)
>
> Bye,
> bearophile

Hi,

Chinese and Japanese people do create large numbers are by grouping 
digits in myriads (every 10,000) rather than the Western thousands (1000) :

http://en.wikipedia.org/wiki/Japanese_numerals#Large_numbers

Thanks to unicode, D has successfuly enabled those people to write their 
identifiers using their own characters if they want to. I don't see why 
we should force them to count the same way as we do (I am European).

Olivier.


More information about the Digitalmars-d mailing list