emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#47302: closed (27.1; calc math-format-number formatting for floats w


From: GNU bug Tracking System
Subject: bug#47302: closed (27.1; calc math-format-number formatting for floats without decimals is unusual)
Date: Tue, 27 Apr 2021 16:16:02 +0000

Your message dated Tue, 27 Apr 2021 18:15:43 +0200
with message-id <58E10359-2CE0-4BF8-936E-47E5DCDA77E4@acm.org>
and subject line Re: bug#47302: 27.1; calc math-format-number formatting for 
floats without decimals is unusual
has caused the debbugs.gnu.org bug report #47302,
regarding 27.1; calc math-format-number formatting for floats without decimals 
is unusual
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
47302: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=47302
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 27.1; calc math-format-number formatting for floats without decimals is unusual Date: Sun, 21 Mar 2021 22:54:50 +0100
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

>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


--- End Message ---
--- Begin Message --- Subject: Re: bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual Date: Tue, 27 Apr 2021 18:15:43 +0200
26 apr. 2021 kl. 16.58 skrev Dave Gillespie <Daveg@synaptics.com>:
> 
> Yes, that patch makes sense.

Good, patch pushed as-is. It can be tweaked later on if needed. Jelle, hope 
this helps.

>  Thanks, and thanks for helping with this old beast!

Happy to give a hand. Nowhere else in Emacs -- and I mean this in the best 
possible way -- do I get a feeling of Mad Science as strongly as when dealing 
with Calc. "Surely Calc doesn't attempt to do this... oh yes. Yes it does."



--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]