From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#48678: [PATCH] lex floats with trailing dot and exponent correctly Date: Wed, 26 May 2021 18:56:43 +0200 Message-ID: <8A11B2EA-B278-4458-A5DB-05E3FB278570@acm.org> Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_670E266A-C6F9-4816-97E0-957543E27ABD" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38172"; mail-complaints-to="usenet@ciao.gmane.io" To: 48678@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 26 18:57:37 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llwqe-0009f3-Ay for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 18:57:36 +0200 Original-Received: from localhost ([::1]:49288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llwqd-0002dw-Dk for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 12:57:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llwq8-0002Ub-50 for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:57:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38249) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llwq7-00009W-46 for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:57:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llwq7-0003mK-3m for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:57:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 May 2021 16:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48678 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162204821514492 (code B ref -1); Wed, 26 May 2021 16:57:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 May 2021 16:56:55 +0000 Original-Received: from localhost ([127.0.0.1]:49793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llwpz-0003lg-5o for submit@debbugs.gnu.org; Wed, 26 May 2021 12:56:55 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:36534) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llwpx-0003lX-3V for submit@debbugs.gnu.org; Wed, 26 May 2021 12:56:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llwpw-0002SC-RF for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:56:52 -0400 Original-Received: from mail71c50.megamailservers.eu ([91.136.10.81]:41278 helo=mail92c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llwpu-0008UK-95 for bug-gnu-emacs@gnu.org; Wed, 26 May 2021 12:56:52 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1622048206; bh=nF+8MFI6KsTVhft1WlVq4DUoceiqlzugWufp6L/BewE=; h=From:Subject:Date:To:From; b=K2/O3SHb7Nj9COpWhuEOFp10JF1pEXCXyqpu5tGmXL/N5pBNTY+S24TW9E1LHgtpu rg1qQytao0WOYTKsB4F6HOYcd2mGvDDENytNLGOM0B1ATVHjwuZ37zqCUDASRQYqwj bNoZrsGLchCniIWopasmyd9aHH+CfkHHTt0MeNws= Feedback-ID: mattiase@acm.or Original-Received: from stanniol.lan (c-b952e353.032-75-73746f71.bbcust.telenor.se [83.227.82.185]) (authenticated bits=0) by mail92c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 14QGuhQI032033 for ; Wed, 26 May 2021 16:56:45 +0000 X-Mailer: Apple Mail (2.3445.104.21) X-CTCH-RefID: str=0001.0A742F27.60AE7DCE.0003, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=UJ+j4xXy c=1 sm=1 tr=0 a=von4qPfY+hyqc0zmWf0tYQ==:117 a=von4qPfY+hyqc0zmWf0tYQ==:17 a=M51BFTxLslgA:10 a=rFiU7r3YT6h7P3ff9FAA:9 a=CjuIK1q_8ugA:10 a=hE2Zma9afcQoTjbWypsA:9 a=B2y7HmGcmWMA:10 X-Origin-Country: SE Received-SPF: softfail client-ip=91.136.10.81; envelope-from=mattiase@acm.org; helo=mail92c50.megamailservers.eu X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207302 Archived-At: --Apple-Mail=_670E266A-C6F9-4816-97E0-957543E27ABD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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. --Apple-Mail=_670E266A-C6F9-4816-97E0-957543E27ABD Content-Disposition: attachment; filename=0001-Fix-lexing-of-numbers-with-trailing-decimal-point-an.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Fix-lexing-of-numbers-with-trailing-decimal-point-an.patch" Content-Transfer-Encoding: quoted-printable =46rom=20a0b69a9fc17c42b0c15b28c5894ffb2a1a9327e3=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Thu,=2020=20May=202021=2018:26:15=20+0200=0A= Subject:=20[PATCH]=20Fix=20lexing=20of=20numbers=20with=20trailing=20= decimal=20point=20and=0A=20exponent=0A=0ANumbers=20with=20a=20trailing=20= dot=20and=20an=20exponent=20were=20incorrectly=20read=20as=0Aintegers=20= (with=20the=20exponent=20ignored)=20instead=20of=20the=20floats=20they=20= should=0Abe.=20=20For=20example,=201.e6=20was=20read=20as=20the=20= integer=201,=20not=201000000.0=20as=0Aevery=20sane=20person=20would=20= agree=20was=20meant.=0A=0ANumbers=20with=20a=20trailing=20dot=20but=20no=20= exponent=20are=20still=20read=20as=0Aintegers.=0A=0A*=20src/lread.c=20= (string_to_number):=20Fix=20float=20lexing.=0A*=20= test/src/lread-tests.el=20(lread-float):=20Add=20test.=0A*=20= doc/lispref/numbers.texi=20(Float=20Basics):=20Clarify=20syntax.=0A---=0A= =20doc/lispref/numbers.texi=20|=20=203=20+-=0A=20src/lread.c=20=20=20=20=20= =20=20=20=20=20=20=20=20=20|=2010=20+++---=0A=20test/src/lread-tests.el=20= =20|=2067=20++++++++++++++++++++++++++++++++++++++++=0A=203=20files=20= changed,=2074=20insertions(+),=206=20deletions(-)=0A=0Adiff=20--git=20= a/doc/lispref/numbers.texi=20b/doc/lispref/numbers.texi=0Aindex=20= 4c5f72126e..d28e15869a=20100644=0A---=20a/doc/lispref/numbers.texi=0A+++=20= b/doc/lispref/numbers.texi=0A@@=20-237,7=20+237,8=20@@=20Float=20Basics=0A= =20@samp{+15e2},=20@samp{15.0e+2},=20@samp{+1500000e-3},=20and=20= @samp{.15e4}=20are=0A=20five=20ways=20of=20writing=20a=20floating-point=20= number=20whose=20value=20is=201500.=0A=20They=20are=20all=20equivalent.=20= =20Like=20Common=20Lisp,=20Emacs=20Lisp=20requires=20at=0A-least=20one=20= digit=20after=20any=20decimal=20point=20in=20a=20floating-point=20= number;=0A+least=20one=20digit=20after=20a=20decimal=20point=20in=20a=20= floating-point=20number=20that=0A+does=20not=20have=20an=20exponent;=0A=20= @samp{1500.}=20is=20an=20integer,=20not=20a=20floating-point=20number.=0A= =20=0A=20=20=20Emacs=20Lisp=20treats=20@code{-0.0}=20as=20numerically=20= equal=20to=20ordinary=20zero=0Adiff=20--git=20a/src/lread.c=20= b/src/lread.c=0Aindex=20bca53a9a37..0b33fd0f25=20100644=0A---=20= a/src/lread.c=0A+++=20b/src/lread.c=0A@@=20-3938,8=20+3938,7=20@@=20= string_to_number=20(char=20const=20*string,=20int=20base,=20ptrdiff_t=20= *plen)=0A=20=20=20bool=20signedp=20=3D=20negative=20|=20positive;=0A=20=20= =20cp=20+=3D=20signedp;=0A=20=0A-=20=20enum=20{=20INTOVERFLOW=20=3D=201,=20= LEAD_INT=20=3D=202,=20DOT_CHAR=20=3D=204,=20TRAIL_INT=20=3D=208,=0A-=09=20= E_EXP=20=3D=2016=20};=0A+=20=20enum=20{=20INTOVERFLOW=20=3D=201,=20= LEAD_INT=20=3D=202,=20TRAIL_INT=20=3D=204,=20E_EXP=20=3D=2016=20};=0A=20=20= =20int=20state=20=3D=200;=0A=20=20=20int=20leading_digit=20=3D=20= digit_to_number=20(*cp,=20base);=0A=20=20=20uintmax_t=20n=20=3D=20= leading_digit;=0A@@=20-3959,7=20+3958,6=20@@=20string_to_number=20(char=20= const=20*string,=20int=20base,=20ptrdiff_t=20*plen)=0A=20=20=20char=20= const=20*after_digits=20=3D=20cp;=0A=20=20=20if=20(*cp=20=3D=3D=20'.')=0A= =20=20=20=20=20{=0A-=20=20=20=20=20=20state=20|=3D=20DOT_CHAR;=0A=20=20=20= =20=20=20=20cp++;=0A=20=20=20=20=20}=0A=20=0A@@=20-4008,8=20+4006,10=20= @@=20string_to_number=20(char=20const=20*string,=20int=20base,=20= ptrdiff_t=20*plen)=0A=20=09=20=20=20=20cp=20=3D=20ecp;=0A=20=09}=0A=20=0A= -=20=20=20=20=20=20float_syntax=20=3D=20((state=20&=20= (DOT_CHAR|TRAIL_INT))=20=3D=3D=20(DOT_CHAR|TRAIL_INT)=0A-=09=09=20=20=20=20= =20=20||=20(state=20&=20~INTOVERFLOW)=20=3D=3D=20(LEAD_INT|E_EXP));=0A+=20= =20=20=20=20=20/*=20A=20float=20has=20digits=20after=20the=20dot=20or=20= an=20exponent.=0A+=09=20This=20excludes=20numbers=20like=20"1."=20which=20= are=20lexed=20as=20integers.=20*/=0A+=20=20=20=20=20=20float_syntax=20=3D=20= ((state=20&=20TRAIL_INT)=0A+=09=09=20=20=20=20=20=20||=20((state=20&=20= LEAD_INT)=20&&=20(state=20&=20E_EXP)));=0A=20=20=20=20=20}=0A=20=0A=20=20= =20if=20(plen)=0Adiff=20--git=20a/test/src/lread-tests.el=20= b/test/src/lread-tests.el=0Aindex=20f2a60bcf32..dac8f95bc4=20100644=0A= ---=20a/test/src/lread-tests.el=0A+++=20b/test/src/lread-tests.el=0A@@=20= -196,4=20+196,71=20@@=20test-inhibit-interaction=0A=20=20=20=20=20= (should-error=20(read-event=20"foo:=20"))=0A=20=20=20=20=20(should-error=20= (read-char-exclusive=20"foo:=20"))))=0A=20=0A+(ert-deftest=20lread-float=20= ()=0A+=20=20(should=20(equal=20(read=20"13")=2013))=0A+=20=20(should=20= (equal=20(read=20"+13")=2013))=0A+=20=20(should=20(equal=20(read=20= "-13")=20-13))=0A+=20=20(should=20(equal=20(read=20"13.")=2013))=0A+=20=20= (should=20(equal=20(read=20"+13.")=2013))=0A+=20=20(should=20(equal=20= (read=20"-13.")=20-13))=0A+=20=20(should=20(equal=20(read=20"13.25")=20= 13.25))=0A+=20=20(should=20(equal=20(read=20"+13.25")=2013.25))=0A+=20=20= (should=20(equal=20(read=20"-13.25")=20-13.25))=0A+=20=20(should=20= (equal=20(read=20".25")=200.25))=0A+=20=20(should=20(equal=20(read=20= "+.25")=200.25))=0A+=20=20(should=20(equal=20(read=20"-.25")=20-0.25))=0A= +=20=20(should=20(equal=20(read=20"13e4")=20130000.0))=0A+=20=20(should=20= (equal=20(read=20"+13e4")=20130000.0))=0A+=20=20(should=20(equal=20(read=20= "-13e4")=20-130000.0))=0A+=20=20(should=20(equal=20(read=20"13e+4")=20= 130000.0))=0A+=20=20(should=20(equal=20(read=20"+13e+4")=20130000.0))=0A= +=20=20(should=20(equal=20(read=20"-13e+4")=20-130000.0))=0A+=20=20= (should=20(equal=20(read=20"625e-4")=200.0625))=0A+=20=20(should=20= (equal=20(read=20"+625e-4")=200.0625))=0A+=20=20(should=20(equal=20(read=20= "-625e-4")=20-0.0625))=0A+=20=20(should=20(equal=20(read=20"1.25e2")=20= 125.0))=0A+=20=20(should=20(equal=20(read=20"+1.25e2")=20125.0))=0A+=20=20= (should=20(equal=20(read=20"-1.25e2")=20-125.0))=0A+=20=20(should=20= (equal=20(read=20"1.25e+2")=20125.0))=0A+=20=20(should=20(equal=20(read=20= "+1.25e+2")=20125.0))=0A+=20=20(should=20(equal=20(read=20"-1.25e+2")=20= -125.0))=0A+=20=20(should=20(equal=20(read=20"1.25e-1")=200.125))=0A+=20=20= (should=20(equal=20(read=20"+1.25e-1")=200.125))=0A+=20=20(should=20= (equal=20(read=20"-1.25e-1")=20-0.125))=0A+=20=20(should=20(equal=20= (read=20"4.e3")=204000.0))=0A+=20=20(should=20(equal=20(read=20"+4.e3")=20= 4000.0))=0A+=20=20(should=20(equal=20(read=20"-4.e3")=20-4000.0))=0A+=20=20= (should=20(equal=20(read=20"4.e+3")=204000.0))=0A+=20=20(should=20(equal=20= (read=20"+4.e+3")=204000.0))=0A+=20=20(should=20(equal=20(read=20= "-4.e+3")=20-4000.0))=0A+=20=20(should=20(equal=20(read=20"5.e-1")=20= 0.5))=0A+=20=20(should=20(equal=20(read=20"+5.e-1")=200.5))=0A+=20=20= (should=20(equal=20(read=20"-5.e-1")=20-0.5))=0A+=20=20(should=20(equal=20= (read=20"0")=200))=0A+=20=20(should=20(equal=20(read=20"+0")=200))=0A+=20= =20(should=20(equal=20(read=20"-0")=200))=0A+=20=20(should=20(equal=20= (read=20"0.")=200))=0A+=20=20(should=20(equal=20(read=20"+0.")=200))=0A+=20= =20(should=20(equal=20(read=20"-0.")=200))=0A+=20=20(should=20(equal=20= (read=20"0.0")=200.0))=0A+=20=20(should=20(equal=20(read=20"+0.0")=20= 0.0))=0A+=20=20(should=20(equal=20(read=20"-0.0")=20-0.0))=0A+=20=20= (should=20(equal=20(read=20"0e5")=200.0))=0A+=20=20(should=20(equal=20= (read=20"+0e5")=200.0))=0A+=20=20(should=20(equal=20(read=20"-0e5")=20= -0.0))=0A+=20=20(should=20(equal=20(read=20"0e-5")=200.0))=0A+=20=20= (should=20(equal=20(read=20"+0e-5")=200.0))=0A+=20=20(should=20(equal=20= (read=20"-0e-5")=20-0.0))=0A+=20=20(should=20(equal=20(read=20".0e-5")=20= 0.0))=0A+=20=20(should=20(equal=20(read=20"+.0e-5")=200.0))=0A+=20=20= (should=20(equal=20(read=20"-.0e-5")=20-0.0))=0A+=20=20(should=20(equal=20= (read=20"0.0e-5")=200.0))=0A+=20=20(should=20(equal=20(read=20"+0.0e-5")=20= 0.0))=0A+=20=20(should=20(equal=20(read=20"-0.0e-5")=20-0.0))=0A+=20=20= (should=20(equal=20(read=20"0.e-5")=200.0))=0A+=20=20(should=20(equal=20= (read=20"+0.e-5")=200.0))=0A+=20=20(should=20(equal=20(read=20"-0.e-5")=20= -0.0))=0A+=20=20)=0A+=0A+=0A=20;;;=20lread-tests.el=20ends=20here=0A--=20= =0A2.21.1=20(Apple=20Git-122.3)=0A=0A= --Apple-Mail=_670E266A-C6F9-4816-97E0-957543E27ABD--