From: Jelle Licht <jlicht@fsfe.org>
To: 47302@debbugs.gnu.org
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 [thread overview]
Message-ID: <86k0q0nped.fsf@fsfe.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 618 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-calc-Fix-formatting-of-floats-without-decimals.patch --]
[-- Type: text/x-patch, Size: 990 bytes --]
From 88e52b073510c86b582487a65fa8ddf52a48e7dd Mon Sep 17 00:00:00 2001
From: Jelle Licht <jlicht@fsfe.org>
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
next reply other threads:[~2021-03-21 21:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-21 21:54 Jelle Licht [this message]
2021-04-21 15:16 ` bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual Stefan Kangas
2021-04-22 13:44 ` Mattias Engdegård
2021-04-22 15:03 ` Jelle Licht
2021-04-22 16:35 ` Dave Gillespie
2021-04-25 15:53 ` Mattias Engdegård
2021-04-26 14:58 ` Dave Gillespie
2021-04-27 16:15 ` Mattias Engdegård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86k0q0nped.fsf@fsfe.org \
--to=jlicht@fsfe.org \
--cc=47302@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).