Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 13, 2014 Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Is it a good idea to accept code like this, to shorten some constants? void main() { int x = 1e6; } Bye, bearophile |
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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?
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | 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.
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | 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. |
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to matovitch Attachments: | 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 :
>
> int x = 1.73e2;
>
> should be allowed but not
>
> int y = 1.73e1;
>
> 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.
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to eles | 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?
|
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolas Sicard | 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. |
September 15, 2014 Re: Integral literals with Exp? | ||||
---|---|---|---|---|
| ||||
Posted in reply to eles | 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
|
Copyright © 1999-2021 by the D Language Foundation