Jump to page: 1 2 3
Thread overview
[Issue 6277] New: Disallow short floating point literals
Jul 10, 2011
Jacob Carlborg
Jul 07, 2012
Jonathan M Davis
Jul 21, 2012
Jonathan M Davis
Jul 21, 2012
Jonathan M Davis
Jul 22, 2012
Walter Bright
Jul 22, 2012
Jonathan M Davis
Jul 22, 2012
Walter Bright
Jul 22, 2012
Jonathan M Davis
Jul 22, 2012
Walter Bright
Jul 23, 2012
Jonathan M Davis
July 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6277

           Summary: Disallow short floating point literals
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-07-09 05:04:51 PDT ---
This comes from bug 3837 and bug 2656


I suggest to turn floating point literals like the following into syntax
errors, because the saving of one digit is not worth the troubles they cause:
.5
3.

And require something like:
0.5
3.0


See also the thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=28030

Daniel Murphy suggests to allow 1.f and 1.L but this a special case.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6277


Jacob Carlborg <doob@me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob@me.com


--- Comment #1 from Jacob Carlborg <doob@me.com> 2011-07-10 02:30:44 PDT ---
1.f will conflict with the UFCS, if it ever gets implemented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #2 from bearophile_hugs@eml.cc 2011-07-10 08:21:56 PDT ---
If this idea gets accepted then I think it's worth changing the other direction too, I mean the default printing of a floating point value with no decimal part:


import std.stdio;
void main() {
    double x = 3.0;
    writeln(x);
}


Currently (2.054beta3. I'd like beta releases to show a progressive beta number
too) this prints:

3

Python here prints 3.0 and I think D is better to do the same, especially if the leading zero becomes required for the FP literals.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 10, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #3 from bearophile_hugs@eml.cc 2011-07-10 13:17:38 PDT ---
The proposal is for hex floating point literals too.

Daniel Murphy suggests to disallow 1._3 too, to help UFCS (Numeric literals cannot *start* with an underscore already).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 11, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #4 from bearophile_hugs@eml.cc 2011-07-11 09:55:45 PDT ---
Steven Schveighoffer reminds this is probably OK (this compiles with DMD
2.054):

void main() {
    auto x = 1f;
    static assert(is(typeof(x) == float));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6277


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #5 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-07 15:23:26 PDT ---
1.f is now illegal as a floating point literal (it's considered to be considered using UFCS). I see no reason to continue to allow .1 or 1.0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #6 from github-bugzilla@puremagic.com 2012-07-21 03:17:30 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/735c2adbda773f8bf6a8ec6bfefe908ab366849e Changes required for issue# 6277.

https://github.com/D-Programming-Language/phobos/commit/17ba4bb5940d579a7306afbfb1d4f26f424fa0aa Merge pull request #708 from jmdavis/6277

Changes required for issue# 6277.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #7 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-21 03:26:53 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1061

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #8 from bearophile_hugs@eml.cc 2012-07-21 05:40:07 PDT ---
(In reply to comment #7)
> https://github.com/D-Programming-Language/dmd/pull/1061

Thank you Jonathan.

Pull 1061 implements half of this request: it disallow "5." and it doesn't disallow ".5"

Another broken symmetry :-)


Is code like this nice looking? In this array one dot is missing by mistake:

void main() {
    double[] a = [.1,.2,.3,.4,.5,6,.7,.8,.9,.10,.11,.12,.13,.14];
}



And in D the leading dot syntax is already used to search in the outer scope:

int x = 5;
void main() {
    int x = 10;
    int y = .x;
    assert(y == 5);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6277



--- Comment #9 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-21 12:02:54 PDT ---
> Pull 1061 implements half of this request: it disallow "5." and it doesn't disallow ".5"

Given the fact that when writing by hand, .5 wouldn't have a 0 on it and the fact that dmd's tests use that syntax heavily, it just didn't seem reasonable to me to force it to be 0.5. It started looking seriously ugly to me to have have every .9999 be 0.9999 and the like. And the more code that would have to change over a minor thing like that, the more likely Walter would be to reject it anyway.

> Is code like this nice looking? In this array one dot is missing by mistake:

Then put the 0's in there. There's nothing stopping you from doing that. Besides, the code isn't broken. It compiles just fine and has the same semantics whether you add that decimal point or not. It's just a question of aesthetics.

> And in D the leading dot syntax is already used to search in the outer scope:

There's no ambiguity there whatsoever, since an identifier can't start with 0.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2 3