all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Eli Barzilay <eli@barzilay.org>
Cc: 41347-done@debbugs.gnu.org, Chris Zheng <chriszheng99@gmail.com>
Subject: bug#41347: 28.0.50; calculator.el: Cannot input negative exponents
Date: Mon, 18 May 2020 11:28:21 +0200	[thread overview]
Message-ID: <4D0C7ECD-7179-435A-9783-08F05E8CC204@acm.org> (raw)
In-Reply-To: <CALO-gutjnuBvtkPoa-4zTdKgwWaL=cWxaYRKjRBDXATah6YkoQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

17 maj 2020 kl. 22.26 skrev Eli Barzilay <eli@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.


[-- Attachment #2: 0001-Fix-calculator-entry-of-numbers-with-negative-expone.patch --]
[-- Type: application/octet-stream, Size: 1574 bytes --]

From 482baa9856e4269bdf8f253621013592bc8de5b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 17 May 2020 18:11:27 +0200
Subject: [PATCH] Fix calculator entry of numbers with negative exponents
 (bug#41347)

* lisp/calculator.el (calculator-string-to-number):
Remove obsolete string transformations preventing entry of 1e-3 etc.
Keep one transformation to allow entry of "1.e3".
Reported by Chris Zheng.
---
 lisp/calculator.el | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/calculator.el b/lisp/calculator.el
index 7e0b2fcc6a..cd92f99268 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -858,12 +858,10 @@ calculator-string-to-number
   "Convert the given STR to a number, according to the value of
 `calculator-input-radix'."
   (if calculator-input-radix
-    (string-to-number str (cadr (assq calculator-input-radix
-                                      '((bin 2) (oct 8) (hex 16)))))
-    (let* ((str (replace-regexp-in-string
-                 "\\.\\([^0-9].*\\)?$" ".0\\1" str))
-           (str (replace-regexp-in-string
-                 "[eE][+-]?\\([^0-9].*\\)?$" "e0\\1" str)))
+      (string-to-number str (cadr (assq calculator-input-radix
+                                        '((bin 2) (oct 8) (hex 16)))))
+    ;; Allow entry of "1.e3".
+    (let ((str (replace-regexp-in-string (rx "." (any "eE")) "e" str)))
       (float (string-to-number str)))))
 
 (defun calculator-push-curnum ()
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2020-05-18  9:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17  5:53 bug#41347: 28.0.50; calculator.el: Cannot input negative exponents Chris Zheng
2020-05-17 11:08 ` 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 [this message]
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=4D0C7ECD-7179-435A-9783-08F05E8CC204@acm.org \
    --to=mattiase@acm.org \
    --cc=41347-done@debbugs.gnu.org \
    --cc=chriszheng99@gmail.com \
    --cc=eli@barzilay.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.