From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual Date: Wed, 21 Apr 2021 10:16:35 -0500 Message-ID: References: <86k0q0nped.fsf@fsfe.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8794"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 47302@debbugs.gnu.org, David Gillespie To: Jelle Licht Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 21 17:17:13 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 1lZEbI-0002CM-Us for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Apr 2021 17:17:12 +0200 Original-Received: from localhost ([::1]:60560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZEbI-0002kA-22 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Apr 2021 11:17:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZEb8-0002jt-Sr for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 11:17:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lZEb8-0002B5-91 for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 11:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lZEb8-0004BT-3i for bug-gnu-emacs@gnu.org; Wed, 21 Apr 2021 11:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Apr 2021 15:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47302 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 47302-submit@debbugs.gnu.org id=B47302.161901820316050 (code B ref 47302); Wed, 21 Apr 2021 15:17:02 +0000 Original-Received: (at 47302) by debbugs.gnu.org; 21 Apr 2021 15:16:43 +0000 Original-Received: from localhost ([127.0.0.1]:59452 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lZEap-0004Ao-4B for submit@debbugs.gnu.org; Wed, 21 Apr 2021 11:16:43 -0400 Original-Received: from mail-pg1-f173.google.com ([209.85.215.173]:33583) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lZEan-0004AZ-A3 for 47302@debbugs.gnu.org; Wed, 21 Apr 2021 11:16:41 -0400 Original-Received: by mail-pg1-f173.google.com with SMTP id t22so30190114pgu.0 for <47302@debbugs.gnu.org>; Wed, 21 Apr 2021 08:16:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc :content-transfer-encoding; bh=Z28Kgo4FUKaoGcD7KHjOFr8jsXjQHyySFepfYmaoASc=; b=RdrIcVupSDAJqXOgTAvnOrSeEqMvVEBazqGX1jInb/elcDRfQD4Um2H4ZJ7dg598Hm cOSRrL+WAENcymdx6qKVnirAlFKPMTt1RbqazqxBwBjHSp6z33k35SqfhiCBsfKxCdlW qMgmjb3Z1IRFK/v0qB1Y+NELon0uwClw7zBvrD9E7dzfTQP4P0a22pU1nukG2jmgcyTJ 7rwGeSez/6e5C13akFFSGuBzU4O58yJipV8/q35wPznDyj2FKh1E3TrMV3ngKrDnl4nD idNjpyHt0GPFFIlqNhJQn4cZJSqlegjsEBA+x/qfaevcKr5R0TPnx/2JNjpeBJfvr81t U4Yw== X-Gm-Message-State: AOAM532SQYZqA2aV9Ggi2fPbZXT2BiVvxcfqReOlFnzUKLfufKCOPKTo mSeqikX9IObzsn/ZHESjq5mcxs9cb6trAhO63ig= X-Google-Smtp-Source: ABdhPJxjAK+UmDzgRQN8od8sufWbApQEtKQOcdu/htpIrRLpVlDw+Px+uSP+iPA4dI4k8jIBWBh19y/LV6xQQlIi02U= X-Received: by 2002:a17:90b:f0b:: with SMTP id br11mr11525176pjb.179.1619018195469; Wed, 21 Apr 2021 08:16:35 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Wed, 21 Apr 2021 10:16:35 -0500 In-Reply-To: <86k0q0nped.fsf@fsfe.org> (Jelle Licht's message of "Sun, 21 Mar 2021 22:54:50 +0100") 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:204631 Archived-At: Jelle Licht writes: > Hey folks, > > I run into the following behaviour when using calc in Emacs 27.1 (using > `emacs -Q'): > > (calc-eval "123.0") ; =3D> "123." > (calc-eval "0.0") ; =3D> "0." > > I would expect this output to be either "123.0" or "123" and "0.0" or > "0" respectively. > > I have attached a super simple patch that fixes this issue for me, but I > am not actually certain of the following: > > - Was this formatting quirk perhaps there with a purpose? > - Does my 'fix' have unintended consequences? Copying in Mattias Engdeg=C3=A5rd in the hope that he can provide some insight here. I also put David Gillespie on Cc. > > Thanks, > Jelle > >>>From 88e52b073510c86b582487a65fa8ddf52a48e7dd Mon Sep 17 00:00:00 2001 > From: Jelle Licht > Date: Sun, 21 Mar 2021 22:39:41 +0100 > Subject: [PATCH] (calc): Fix formatting of floats without decimals > > * lisp/calc/calc.el (math-format-number): Fix formatting for floats > without decimals. > --- > lisp/calc/calc.el | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el > index ec09abb34c..fac9f70915 100644 > --- a/lisp/calc/calc.el > +++ b/lisp/calc/calc.el > @@ -3193,8 +3193,9 @@ math-format-number > ((=3D dpos 0) > (setq str (concat "0" point str))) > ((and (<=3D exp 0) (> dpos 0)) > - (setq str (concat (substring str 0 dpos) point > - (substring str dpos)))) > + (when (> len dpos) > + (setq str (concat (substring str 0 dpos) point > + (substring str dpos))))) > ((> exp 0) > (setq str (concat str (make-string exp ?0) point))) > (t ; (< dpos 0)