unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: peder@klingenberg.no (Peder O. Klingenberg)
To: 25255@debbugs.gnu.org
Subject: bug#25255: Emacs calculator evalutes lcm to a negative number
Date: Sun, 05 Feb 2017 11:28:17 +0100	[thread overview]
Message-ID: <m1efzdylry.fsf@klingenberg.no> (raw)
In-Reply-To: <112161482489139@web25j.yandex.ru> (Bug Poster's message of "Fri,  23 Dec 2016 19:32:19 +0900")

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

  reply	other threads:[~2017-02-05 10:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2017-02-24  1:30   ` Glenn Morris

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m1efzdylry.fsf@klingenberg.no \
    --to=peder@klingenberg.no \
    --cc=25255@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 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).