GNU bug report logs - #48678
[PATCH] lex floats with trailing dot and exponent correctly

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattiase <at> acm.org>

Date: Wed, 26 May 2021 16:57:02 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 48678 in the body.
You can then email your comments to 48678 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Wed, 26 May 2021 16:57:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mattias Engdegård <mattiase <at> acm.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 May 2021 16:57:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] lex floats with trailing dot and exponent correctly
Date: Wed, 26 May 2021 18:56:43 +0200
[Message part 1 (text/plain, inline)]
Motivation: I poured lots of numeric data into Emacs for a computation, but the result weren't as expected at all. Yet my code was correct, and so was the data.

After hours of debugging, it turned out that Emacs reads a number like 1.e6 as the integer 1, not the float 1000000.0. The exponent is silently ignored!

Now Emacs has always treated numbers like 123. as integers rather than floats, but
(1) it's documented,
(2) it's what Common Lisp does, and
(3) it actually doesn't affect the numeric value most of the time.

(Common Lisp probably got this from Maclisp, the rationale being that a trailing dot can be used to write integers in base 10 even when the current input radix is set to something else, something that Emacs Lisp doesn't need.)

Obviously this doesn't apply to 1.e6 which any sane person agrees is the float 1.0e+6 (including Common Lisp).

The attached patch fixes this bug.

[0001-Fix-lexing-of-numbers-with-trailing-decimal-point-an.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Wed, 26 May 2021 17:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Wed, 26 May 2021 20:27:17 +0300
> From: Mattias Engdegård <mattiase <at> acm.org>
> Date: Wed, 26 May 2021 18:56:43 +0200
> 
> Now Emacs has always treated numbers like 123. as integers rather than floats, but
> (1) it's documented,
> (2) it's what Common Lisp does, and
> (3) it actually doesn't affect the numeric value most of the time.
> 
> (Common Lisp probably got this from Maclisp, the rationale being that a trailing dot can be used to write integers in base 10 even when the current input radix is set to something else, something that Emacs Lisp doesn't need.)
> 
> Obviously this doesn't apply to 1.e6 which any sane person agrees is the float 1.0e+6 (including Common Lisp).
> 
> The attached patch fixes this bug.

Brace for massive breakage.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Wed, 26 May 2021 22:14:01 GMT) Full text and rfc822 format available.

Message #11 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Mattias Engdegård <mattiase <at> acm.org>,
 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 00:13:33 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

>> Obviously this doesn't apply to 1.e6 which any sane person agrees is
>> the float 1.0e+6 (including Common Lisp).
>> 
>> The attached patch fixes this bug.
>
> Brace for massive breakage.

Yes, it's a rather scary change -- people will have code that sloppily
parses noisy things like "1foo" and expect to get a 1 out, and ".e6"
could well be noise that they expect to have ignored.

So I'm sceptical.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 07:33:02 GMT) Full text and rfc822 format available.

Message #14 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Mattias Engdegård <mattiase <at> acm.org>,
 Eli Zaretskii <eliz <at> gnu.org>, 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 09:32:53 +0200
On Mai 27 2021, Lars Ingebrigtsen wrote:

> Yes, it's a rather scary change -- people will have code that sloppily
> parses noisy things like "1foo" and expect to get a 1 out, and ".e6"
> could well be noise that they expect to have ignored.
>
> So I'm sceptical.

But then 1.e6 should be parsed as a symbol.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 07:41:02 GMT) Full text and rfc822 format available.

Message #17 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: Mattias Engdegård <mattiase <at> acm.org>,
 Eli Zaretskii <eliz <at> gnu.org>, 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 09:40:19 +0200
Andreas Schwab <schwab <at> linux-m68k.org> writes:

> On Mai 27 2021, Lars Ingebrigtsen wrote:
>
>> Yes, it's a rather scary change -- people will have code that sloppily
>> parses noisy things like "1foo" and expect to get a 1 out, and ".e6"
>> could well be noise that they expect to have ignored.
>>
>> So I'm sceptical.
>
> But then 1.e6 should be parsed as a symbol.

Oops, I thought this was about string-to-number, which it wasn't at all.

Hm.  Currently 1.e6 reads to 1?  Weird.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 12:21:02 GMT) Full text and rfc822 format available.

Message #20 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 14:20:14 +0200
26 maj 2021 kl. 19.27 skrev Eli Zaretskii <eliz <at> gnu.org>:

> Brace for massive breakage.

Challenge accepted! Now in master. Bring it on!





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 12:29:02 GMT) Full text and rfc822 format available.

Message #23 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 48678 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>,
 Andreas Schwab <schwab <at> linux-m68k.org>
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 14:28:17 +0200
27 maj 2021 kl. 09.40 skrev Lars Ingebrigtsen <larsi <at> gnus.org>:

> Hm.  Currently 1.e6 reads to 1?  Weird.

Yes, this behaviour was probably not intended at all. Such things happen; the best we can do is to put things right.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 12:38:02 GMT) Full text and rfc822 format available.

Message #26 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Mattias Engdegård <mattiase <at> acm.org>,
 48678 <at> debbugs.gnu.org, Andreas Schwab <schwab <at> linux-m68k.org>
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 14:36:48 +0200
Am Do., 27. Mai 2021 um 09:41 Uhr schrieb Lars Ingebrigtsen <larsi <at> gnus.org>:
>
> Andreas Schwab <schwab <at> linux-m68k.org> writes:
>
> > On Mai 27 2021, Lars Ingebrigtsen wrote:
> >
> >> Yes, it's a rather scary change -- people will have code that sloppily
> >> parses noisy things like "1foo" and expect to get a 1 out, and ".e6"
> >> could well be noise that they expect to have ignored.
> >>
> >> So I'm sceptical.
> >
> > But then 1.e6 should be parsed as a symbol.
>
> Oops, I thought this was about string-to-number, which it wasn't at all.
>
> Hm.  Currently 1.e6 reads to 1?  Weird.

At least for me it's parsed as a symbol.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Thu, 27 May 2021 12:38:02 GMT) Full text and rfc822 format available.

Message #29 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Philipp Stephani <p.stephani2 <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Mattias Engdegård <mattiase <at> acm.org>,
 48678 <at> debbugs.gnu.org, Andreas Schwab <schwab <at> linux-m68k.org>
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Thu, 27 May 2021 14:37:42 +0200
Am Do., 27. Mai 2021 um 14:36 Uhr schrieb Philipp Stephani
<p.stephani2 <at> gmail.com>:
>
> Am Do., 27. Mai 2021 um 09:41 Uhr schrieb Lars Ingebrigtsen <larsi <at> gnus.org>:
> >
> > Andreas Schwab <schwab <at> linux-m68k.org> writes:
> >
> > > On Mai 27 2021, Lars Ingebrigtsen wrote:
> > >
> > >> Yes, it's a rather scary change -- people will have code that sloppily
> > >> parses noisy things like "1foo" and expect to get a 1 out, and ".e6"
> > >> could well be noise that they expect to have ignored.
> > >>
> > >> So I'm sceptical.
> > >
> > > But then 1.e6 should be parsed as a symbol.
> >
> > Oops, I thought this was about string-to-number, which it wasn't at all.
> >
> > Hm.  Currently 1.e6 reads to 1?  Weird.
>
> At least for me it's parsed as a symbol.

Oops, taking that back, I checked 1e.6 instead of 1.e6.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Sat, 29 May 2021 06:04:02 GMT) Full text and rfc822 format available.

Message #32 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Sat, 29 May 2021 08:03:42 +0200
Mattias Engdegård <mattiase <at> acm.org> writes:

> 26 maj 2021 kl. 19.27 skrev Eli Zaretskii <eliz <at> gnu.org>:
>
>> Brace for massive breakage.
>
> Challenge accepted! Now in master. Bring it on!

:-)

There didn't seem to be any reported breakages from this yet.  It does
seem quite NEWS-worthy, though, so I've added an entry, and I'm closing
this bug report.  If serious breakages do happen, we should consider
backing out the change.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 06:04:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 48678 <at> debbugs.gnu.org and Mattias Engdegård <mattiase <at> acm.org> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 06:04:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Sat, 29 May 2021 07:48:01 GMT) Full text and rfc822 format available.

Message #39 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Sat, 29 May 2021 09:47:39 +0200
29 maj 2021 kl. 08.03 skrev Lars Ingebrigtsen <larsi <at> gnus.org>:

> There didn't seem to be any reported breakages from this yet.  It does
> seem quite NEWS-worthy, though, so I've added an entry, and I'm closing
> this bug report.

Excellent! I was going to write a NEWS entry, so thank you for forcing my hand. I took the liberty to make a few minor changes to it for precision; if it isn't to your liking, do tell.

>  If serious breakages do happen, we should consider
> backing out the change.

Most certainly, but I'm confident in the change. It wasn't done without serious preparation: I scanned hundreds of Emacs packages, and checked all boolean combinations in the reader condition to guarantee correctness (which showed that a flag in the condition was redundant and could be removed). There is now a serious test.

Looking for the origin I also ran Maclisp on a PDP-10 and can confirm that it does not have the bug, so it must have been endogenous to Emacs.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48678; Package emacs. (Sun, 30 May 2021 04:08:02 GMT) Full text and rfc822 format available.

Message #42 received at 48678 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 48678 <at> debbugs.gnu.org
Subject: Re: bug#48678: [PATCH] lex floats with trailing dot and exponent
 correctly
Date: Sun, 30 May 2021 06:07:50 +0200
Mattias Engdegård <mattiase <at> acm.org> writes:

> Excellent! I was going to write a NEWS entry, so thank you for forcing
> my hand. I took the liberty to make a few minor changes to it for
> precision; if it isn't to your liking, do tell.

Looks good to me; thanks.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 27 Jun 2021 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 303 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.