GNU bug report logs -
#41347
28.0.50; calculator.el: Cannot input negative exponents
Previous Next
Reported by: Chris Zheng <chriszheng99 <at> gmail.com>
Date: Sun, 17 May 2020 05:54:02 UTC
Severity: normal
Found in version 28.0.50
Done: Mattias Engdegård <mattiase <at> acm.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Mon, 18 May 2020 11:28:21 +0200
with message-id <4D0C7ECD-7179-435A-9783-08F05E8CC204 <at> acm.org>
and subject line Re: bug#41347: 28.0.50; calculator.el: Cannot input negative exponents
has caused the debbugs.gnu.org bug report #41347,
regarding 28.0.50; calculator.el: Cannot input negative exponents
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
41347: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=41347
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Hello,
With current master, starting Emacs with `-Q`:
1. M-x calculator
2. Input 1e-3 RET
You will get 1 instead of 0.001. I believe this happens since Emacs 26.1. The root cause is the `calculator-string-to-number` function in lisp/calculator.el. Now the function gives
(calculator-string-to-number "1e-3") => 1.0
(calculator-string-to-number "1e3") => 1000.0
(calculator-string-to-number "1e") => 1.0
The funcional code is
(replace-regexp-in-string
"[eE][+-]?\\([^0-9].*\\)?$" "e0\\1" str)
It changes `1e-3` to `1e0-3` that is recognized as 1. I have a possible fix attached below. Please see if it is correct.
Thank you,
Chris Zheng
From 7693d7072e4787c4b0663f490be5d83c1d9a6ee3 Mon Sep 17 00:00:00 2001
From: Chris Zheng <chriszheng99 <at> gmail.com>
Date: Sun, 17 May 2020 13:43:35 +0800
Subject: [PATCH 1/1] Fix calculator exponent input
* lisp/calculator.el (calculator-string-to-number): Change the regexp
to correctly deal with negative exponents.
---
lisp/calculator.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/calculator.el b/lisp/calculator.el
index 7e0b2fcc6a..fa3eb19099 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -863,7 +863,7 @@ calculator-string-to-number
(let* ((str (replace-regexp-in-string
"\\.\\([^0-9].*\\)?$" ".0\\1" str))
(str (replace-regexp-in-string
- "[eE][+-]?\\([^0-9].*\\)?$" "e0\\1" str)))
+ "[eE]\\([+-]?\\)?$" "e\\10" str)))
(float (string-to-number str)))))
(defun calculator-push-curnum ()
--
2.16.1.windows.1
[Message part 3 (message/rfc822, inline)]
[Message part 4 (text/plain, inline)]
17 maj 2020 kl. 22.26 skrev Eli Barzilay <eli <at> barzilay.org>:
> the idea is to mimic common calculators
> where you can type "3." or "3e" and get 3.
Thank you Eli! I can confirm that after removing all the string transformation prior to the call to string-to-number, everything works as expected except "1.e3" (dot before E). A single transformation taking care of that case was added for the sake of completeness.
The attached patch has now been pushed to master.
[0001-Fix-calculator-entry-of-numbers-with-negative-expone.patch (application/octet-stream, attachment)]
This bug report was last modified 5 years and 5 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.