unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 3843711 3/3: Simplify calculator-expt
       [not found] ` <20191105074004.5063220A3C@vcs0.savannah.gnu.org>
@ 2019-11-05 11:28   ` Juanma Barranquero
  2019-11-05 21:45     ` Paul Eggert
  2019-11-05 19:29   ` Stefan Monnier
  1 sibling, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2019-11-05 11:28 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Emacs developers

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

On Tue, Nov 5, 2019 at 8:40 AM Paul Eggert <eggert@cs.ucla.edu> wrote:

> +    (overflow-error
> +     (if (or (natnump x) (cl-evenp y))
> +        1.0e+INF
> +       -1.0e+INF))))

That introduces a run-time dependency on cl-lib:

  ELC      calculator.elc

In end of data:
calculator.el:1644:1:Warning: the function `cl-evenp' might not be defined
at
    runtime.

[-- Attachment #2: Type: text/html, Size: 540 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 3843711 3/3: Simplify calculator-expt
       [not found] ` <20191105074004.5063220A3C@vcs0.savannah.gnu.org>
  2019-11-05 11:28   ` Juanma Barranquero
@ 2019-11-05 19:29   ` Stefan Monnier
  2019-11-05 21:47     ` Paul Eggert
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-11-05 19:29 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel

> -           ((eq (logand (truncate y) 1) 1)   ; expansion of cl `oddp'
> [...]
> +     (if (or (natnump x) (cl-evenp y))

`cl-evenp` doesn't do the `truncate` part, so this will signal an error if
`x` is not a natural number and `y` is not an integer.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 3843711 3/3: Simplify calculator-expt
  2019-11-05 11:28   ` Juanma Barranquero
@ 2019-11-05 21:45     ` Paul Eggert
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Eggert @ 2019-11-05 21:45 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

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

On 11/5/19 3:28 AM, Juanma Barranquero wrote:

> calculator.el:1644:1:Warning: the function `cl-evenp' might not be 
> defined at runtime.
Thanks, I installed the attached to pacify the byte-compiler about that. 
(Remind me again why cl-lib is not preloaded? :-)

[-- Attachment #2: 0001-Pacify-byte-compiler-in-calculator.el.patch --]
[-- Type: text/x-patch, Size: 1139 bytes --]

From f28d1b1f9491c95319b7073d29bb67c0f5431145 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 5 Nov 2019 13:43:44 -0800
Subject: [PATCH] Pacify byte-compiler in calculator.el
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/calculator.el (calculator-expt): Open-code cl-evenp to
pacify warning “the function ‘cl-evenp’ might not be defined”.
Problem reported by Juanma Barranquero in:
https://lists.gnu.org/r/emacs-devel/2019-11/msg00118.html
---
 lisp/calculator.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/calculator.el b/lisp/calculator.el
index fab365d5f2..6c07ee2225 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -1620,7 +1620,9 @@ calculator-expt
   (condition-case nil
       (expt x y)
     (overflow-error
-     (if (or (natnump x) (cl-evenp y))
+     ;; X and Y must be integers, as expt silently returns floating-point
+     ;; infinity on floating-point overflow.
+     (if (or (natnump x) (zerop (logand x 1)))
 	 1.0e+INF
        -1.0e+INF))))
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: master 3843711 3/3: Simplify calculator-expt
  2019-11-05 19:29   ` Stefan Monnier
@ 2019-11-05 21:47     ` Paul Eggert
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Eggert @ 2019-11-05 21:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 11/5/19 11:29 AM, Stefan Monnier wrote:

>> +     (if (or (natnump x) (cl-evenp y))
> 
> `cl-evenp` doesn't do the `truncate` part, so this will signal an error if
> `x` is not a natural number and `y` is not an integer.

Not a problem, as this part of the code is reachable only if Y is an 
integer. I added a comment to that effect.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: master 3843711 3/3: Simplify calculator-expt
@ 2020-04-16 20:36 jakub-w
  2020-04-16 20:56 ` Paul Eggert
  0 siblings, 1 reply; 6+ messages in thread
From: jakub-w @ 2020-04-16 20:36 UTC (permalink / raw)
  To: Paul Eggert; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 140 bytes --]

Good thing I decided to read the mailing list 5 months after the patch
was submitted. There was a typo that would be pretty hard to catch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Fix-a-typo-in-calculator.el.patch --]
[-- Type: text/x-patch, Size: 941 bytes --]

From 9acd26cf70decf20240f5485d6f12f4cf22c2a80 Mon Sep 17 00:00:00 2001
From: jakub-w <jakub-w@riseup.net>
Date: Thu, 16 Apr 2020 22:07:14 +0200
Subject: [PATCH] Fix a typo in calculator.el

* lisp/calculator.el (calculator-expt): Overflowing exponentiation
caused the function to return -1.0e+INF if the base was an odd,
negative number, no matter what the exponent was.
---
 lisp/calculator.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/calculator.el b/lisp/calculator.el
index c1af26ffcc..6996990814 100644
--- a/lisp/calculator.el
+++ b/lisp/calculator.el
@@ -1622,7 +1622,7 @@ calculator-expt
     (overflow-error
      ;; X and Y must be integers, as expt silently returns floating-point
      ;; infinity on floating-point overflow.
-     (if (or (natnump x) (zerop (logand x 1)))
+     (if (or (natnump x) (zerop (logand y 1)))
 	 1.0e+INF
        -1.0e+INF))))
 
-- 
2.26.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: master 3843711 3/3: Simplify calculator-expt
  2020-04-16 20:36 master 3843711 3/3: Simplify calculator-expt jakub-w
@ 2020-04-16 20:56 ` Paul Eggert
  0 siblings, 0 replies; 6+ messages in thread
From: Paul Eggert @ 2020-04-16 20:56 UTC (permalink / raw)
  To: jakub-w; +Cc: emacs-devel

On 4/16/20 1:36 PM, jakub-w@riseup.net wrote:
> Good thing I decided to read the mailing list 5 months after the patch
> was submitted. There was a typo that would be pretty hard to catch.

Thanks for catching that typo. Since it's a regression that I introduced in 
November, I installed the patch into the emacs-27 branch; in due course the 
patch should be merged into Emacs master.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-04-16 20:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 20:36 master 3843711 3/3: Simplify calculator-expt jakub-w
2020-04-16 20:56 ` Paul Eggert
     [not found] <20191105073959.21509.71385@vcs0.savannah.gnu.org>
     [not found] ` <20191105074004.5063220A3C@vcs0.savannah.gnu.org>
2019-11-05 11:28   ` Juanma Barranquero
2019-11-05 21:45     ` Paul Eggert
2019-11-05 19:29   ` Stefan Monnier
2019-11-05 21:47     ` Paul Eggert

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).