* bug#25255: Emacs calculator evalutes lcm to a negative number
@ 2016-12-23 10:32 Bug Poster
2017-02-05 10:28 ` Peder O. Klingenberg
0 siblings, 1 reply; 3+ messages in thread
From: Bug Poster @ 2016-12-23 10:32 UTC (permalink / raw)
To: 25255
GNU Emacs 24.3.1
This is formula of Least Common Multiple:
lcm(a, b) = |a * b| / gcd(a, b)
The calculator evaluates it, but doesn't take its absolute value.
Input:
5
n
<RET>
4
k
l
Output:
1: -20
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#25255: Emacs calculator evalutes lcm to a negative number
2016-12-23 10:32 bug#25255: Emacs calculator evalutes lcm to a negative number Bug Poster
@ 2017-02-05 10:28 ` Peder O. Klingenberg
2017-02-24 1:30 ` Glenn Morris
0 siblings, 1 reply; 3+ messages in thread
From: Peder O. Klingenberg @ 2017-02-05 10:28 UTC (permalink / raw)
To: 25255
[-- Attachment #1: Type: text/plain, Size: 262 bytes --]
Bug Poster <bugzilla-mail-box@yandex.ru> writes:
> This is formula of Least Common Multiple:
>
> lcm(a, b) = |a * b| / gcd(a, b)
I agree, every textbook I can find defines lcm to return a positive
integer. Here's a patch, which hopefully someone will apply.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-LCM-is-defined-to-return-a-positive-integer.patch --]
[-- Type: text/x-patch, Size: 1504 bytes --]
From de52ee092bc0ab7c94d9270b9c3160c0923a68c0 Mon Sep 17 00:00:00 2001
From: "Peder O. Klingenberg" <peder@klingenberg.no>
Date: Sun, 5 Feb 2017 10:58:00 +0100
Subject: [PATCH] LCM is defined to return a positive integer.
Bug#25255:
* doc/misc/calc.texi (Combinatorial Functions): The product of
LCM and GCD is an absolute value.
* lisp/calc/calc-comb.el (calcFunc-lcm): Use absolute values.
---
doc/misc/calc.texi | 4 ++--
lisp/calc/calc-comb.el | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi
index baf46f7170..7bd060189c 100644
--- a/doc/misc/calc.texi
+++ b/doc/misc/calc.texi
@@ -19111,8 +19111,8 @@ Combinatorial Functions
@tindex lcm
The @kbd{k l} (@code{calc-lcm}) [@code{lcm}] command computes the
Least Common Multiple of two integers or fractions. The product of
-the LCM and GCD of two numbers is equal to the product of the
-numbers.
+the LCM and GCD of two numbers is equal to the absolute value of the
+product of the numbers.
@kindex k E
@pindex calc-extended-gcd
diff --git a/lisp/calc/calc-comb.el b/lisp/calc/calc-comb.el
index bc1ac315a0..c84ff23685 100644
--- a/lisp/calc/calc-comb.el
+++ b/lisp/calc/calc-comb.el
@@ -260,7 +260,7 @@ calcFunc-gcd
(defun calcFunc-lcm (a b)
(let ((g (calcFunc-gcd a b)))
(if (Math-numberp g)
- (math-div (math-mul a b) g)
+ (math-div (math-abs (math-mul a b)) g)
(list 'calcFunc-lcm a b))))
(defun calcFunc-egcd (a b) ; Knuth section 4.5.2
--
2.11.0
[-- Attachment #3: Type: text/plain, Size: 17 bytes --]
--
...Peder...
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#25255: Emacs calculator evalutes lcm to a negative number
2017-02-05 10:28 ` Peder O. Klingenberg
@ 2017-02-24 1:30 ` Glenn Morris
0 siblings, 0 replies; 3+ messages in thread
From: Glenn Morris @ 2017-02-24 1:30 UTC (permalink / raw)
To: Peder O. Klingenberg; +Cc: bugzilla-mail-box, 25255
Peder O. Klingenberg wrote:
> I agree, every textbook I can find defines lcm to return a positive
> integer. Here's a patch, which hopefully someone will apply.
Thanks; applied as f6d2ba7.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-24 1:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-23 10:32 bug#25255: Emacs calculator evalutes lcm to a negative number Bug Poster
2017-02-05 10:28 ` Peder O. Klingenberg
2017-02-24 1:30 ` Glenn Morris
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).