all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chris Zheng <chriszheng99@gmail.com>
To: 41347@debbugs.gnu.org
Subject: bug#41347: 28.0.50; calculator.el: Cannot input negative exponents
Date: Sun, 17 May 2020 13:53:12 +0800	[thread overview]
Message-ID: <20200517055312.jtwughazs453lbzt@Kael> (raw)

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@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






             reply	other threads:[~2020-05-17  5:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17  5:53 Chris Zheng [this message]
2020-05-17 11:08 ` bug#41347: 28.0.50; calculator.el: Cannot input negative exponents Mattias Engdegård
2020-05-17 11:57   ` Andreas Schwab
2020-05-17 12:18     ` Mattias Engdegård
2020-05-17 20:26   ` Eli Barzilay
2020-05-18  9:28     ` Mattias Engdegård
2020-05-18 15:01       ` Chris Zheng
2020-05-18 15:11         ` Mattias Engdegård
2020-05-18 19:19       ` Eli Barzilay

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200517055312.jtwughazs453lbzt@Kael \
    --to=chriszheng99@gmail.com \
    --cc=41347@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.