From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jelle Licht Newsgroups: gmane.emacs.bugs Subject: bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual Date: Sun, 21 Mar 2021 22:54:50 +0100 Message-ID: <86k0q0nped.fsf@fsfe.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25275"; mail-complaints-to="usenet@ciao.gmane.io" To: 47302@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 21 22:55:19 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 1lO62Z-0006TR-MT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 22:55:19 +0100 Original-Received: from localhost ([::1]:42280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lO62Y-0007gm-BG for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Mar 2021 17:55:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO62K-0007gW-00 for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:55:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lO62I-0007Tc-S6 for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:55:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lO62I-0002o0-Pq for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jelle Licht Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Mar 2021 21:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47302 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161636370210778 (code B ref -1); Sun, 21 Mar 2021 21:55:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Mar 2021 21:55:02 +0000 Original-Received: from localhost ([127.0.0.1]:55586 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lO62H-0002nf-M8 for submit@debbugs.gnu.org; Sun, 21 Mar 2021 17:55:02 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:43892) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lO62G-0002nY-6k for submit@debbugs.gnu.org; Sun, 21 Mar 2021 17:55:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO62E-0007gA-Ed for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:54:59 -0400 Original-Received: from mail1.fsfe.org ([2001:aa8:ffed:f5f3::151]:59802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO62C-0007PH-IO for bug-gnu-emacs@gnu.org; Sun, 21 Mar 2021 17:54:58 -0400 Received-SPF: pass client-ip=2001:aa8:ffed:f5f3::151; envelope-from=jlicht@fsfe.org; helo=mail1.fsfe.org X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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:202811 Archived-At: --=-=-= Content-Type: text/plain Hey folks, I run into the following behaviour when using calc in Emacs 27.1 (using `emacs -Q'): --8<---------------cut here---------------start------------->8--- (calc-eval "123.0") ; => "123." (calc-eval "0.0") ; => "0." --8<---------------cut here---------------end--------------->8--- 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? Thanks, Jelle --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-calc-Fix-formatting-of-floats-without-decimals.patch >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 ((= dpos 0) (setq str (concat "0" point str))) ((and (<= 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) -- 2.31.0 --=-=-=--