www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Integral literals with Exp?

reply "bearophile" <bearophileHUGS lycos.com> writes:
Is it a good idea to accept code like this, to shorten some 
constants?

void main() {
     int x = 1e6;
}

Bye,
bearophile
Sep 13 2014
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 9/13/2014 12:23 AM, bearophile wrote:
 Is it a good idea to accept code like this, to shorten some constants?

 void main() {
      int x = 1e6;
 }
1_000_000 solves that problem.
Sep 14 2014
parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 Is it a good idea to accept code like this, to shorten some 
 constants?

 void main() {
     int x = 1e6;
 }
1_000_000 solves that problem.
How does adding extra _s help with shortening constants?
Sep 15 2014
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 9/15/2014 1:54 AM, John Colvin wrote:
 On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 Is it a good idea to accept code like this, to shorten some constants?

 void main() {
     int x = 1e6;
 }
1_000_000 solves that problem.
How does adding extra _s help with shortening constants?
Readability is the goal, not minimizing the number of characters.
Sep 15 2014
parent reply "eles" <eles eles.com> writes:
On Monday, 15 September 2014 at 09:13:52 UTC, Walter Bright wrote:
 On 9/15/2014 1:54 AM, John Colvin wrote:
 On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright 
 wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 Readability is the goal, not minimizing the number of 
 characters.
Exactly: 6.02214129×10^23 http://en.wikipedia.org/wiki/Avogadro_constant Some constants are widely known in the eXX form.
Sep 15 2014
parent reply "Nicolas Sicard" <dransic gmail.com> writes:
On Monday, 15 September 2014 at 09:19:12 UTC, eles wrote:
 On Monday, 15 September 2014 at 09:13:52 UTC, Walter Bright 
 wrote:
 On 9/15/2014 1:54 AM, John Colvin wrote:
 On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright 
 wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 Readability is the goal, not minimizing the number of 
 characters.
Exactly: 6.02214129×10^23 http://en.wikipedia.org/wiki/Avogadro_constant Some constants are widely known in the eXX form.
What integral type would hold that value?
Sep 15 2014
parent reply "eles" <eles eles.com> writes:
On Monday, 15 September 2014 at 11:31:26 UTC, Nicolas Sicard 
wrote:
 On Monday, 15 September 2014 at 09:19:12 UTC, eles wrote:
 On Monday, 15 September 2014 at 09:13:52 UTC, Walter Bright 
 wrote:
 On 9/15/2014 1:54 AM, John Colvin wrote:
 On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright 
 wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 What integral type would hold that value?
Good question. This one, of course: http://en.wikipedia.org/wiki/Mole_(unit) Just joking.
Sep 15 2014
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 9/15/14, 4:48 AM, eles wrote:
 On Monday, 15 September 2014 at 11:31:26 UTC, Nicolas Sicard wrote:
 On Monday, 15 September 2014 at 09:19:12 UTC, eles wrote:
 On Monday, 15 September 2014 at 09:13:52 UTC, Walter Bright wrote:
 On 9/15/2014 1:54 AM, John Colvin wrote:
 On Monday, 15 September 2014 at 00:54:40 UTC, Walter Bright wrote:
 On 9/13/2014 12:23 AM, bearophile wrote:
 What integral type would hold that value?
Good question. This one, of course: http://en.wikipedia.org/wiki/Mole_(unit) Just joking.
Nice :o). To the original idea, the short answer would be no. -- Andrei
Sep 15 2014
prev sibling parent reply "matovitch" <camille.brugel laposte.net> writes:
On Saturday, 13 September 2014 at 07:23:39 UTC, bearophile wrote:
 Is it a good idea to accept code like this, to shorten some 
 constants?

 void main() {
     int x = 1e6;
 }

 Bye,
 bearophile
Well, I guess it wouldn't help the lexer. To be consistent : int x = 1.73e2; should be allowed but not int y = 1.73e1; Not a good idea IMHO.
Sep 15 2014
parent ketmar via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Mon, 15 Sep 2014 09:05:09 +0000
matovitch via Digitalmars-d <digitalmars-d puremagic.com> wrote:

 Well, I guess it wouldn't help the lexer. To be consistent :
=20
 int x =3D 1.73e2;
=20
 should be allowed but not
=20
 int y =3D 1.73e1;
=20
 Not a good idea IMHO.
both numbers aren't ints. the first is obviously "173.0", not "173". more convoluted sample: is "1000e-3" represents "1" or "1.0"? for all my scripting languages where having separated ints and floats makes any sense, i'm using this rules: 1. number with point in it is always float. 2. number with negative exponent is always float.
Sep 15 2014