From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Calculator: no exponent, full number ? Date: Thu, 06 Jun 2019 17:47:44 +0200 Message-ID: <875zpibtr3.fsf@mbork.pl> References: <20190604154307.565d33cf@mistral> <87zhmwzn67.fsf@mbork.pl> <20190605095317.499f2082@mistral> <86tvd3sig6.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="114477"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.1.0; emacs 27.0.50 Cc: help-gnu-emacs@gnu.org, Ingemar Holmgren To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 06 17:52:08 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYugQ-000Tdn-Sy for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 17:52:07 +0200 Original-Received: from localhost ([127.0.0.1]:34346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYugP-0000Cp-UX for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 11:52:05 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:47486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYufq-0008R4-B9 for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 11:51:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYufo-00081i-BS for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 11:51:30 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:42470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYufm-0007PX-W7 for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 11:51:28 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id A4FCFE662D; Thu, 6 Jun 2019 17:51:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 17JVOTu8fFrQ; Thu, 6 Jun 2019 17:51:00 +0200 (CEST) Original-Received: from localhost (83.25.99.3.ipv4.supernova.orange.pl [83.25.99.3]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 37E84E662B; Thu, 6 Jun 2019 17:51:00 +0200 (CEST) In-reply-to: <86tvd3sig6.fsf@zoho.eu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.110.48.8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120778 Archived-At: On 2019-06-06, at 01:47, Emanuel Berg via help-gnu-emacs wrote: > (defun hypotenuse (c1 c2) > (sqrt (+ (* c1 c1) (* c2 c2))) ) Just for the fun, let me mention that this is not a very good algorithm for computing the Pythagorean sum - it may happen that both the operands and the result lie within the bounds for the given type, but this calculation blows up because of large squares overflowing. Also, it is slow because of the need to compute square roots. Interestingly, there exists a clever algorithm that does not have these problems. It is used (among others) in Donald Knuth's METAFONT. The algorithm is described in the paper (using Emanuel's favorite format;-)): @ARTICLE{5390405, author={C. {Moler} and D. {Morrison}}, journal={IBM Journal of Research and Development}, title={Replacing Square Roots by Pythagorean Sums}, year={1983}, volume={27}, number={6}, pages={577-581}, keywords={}, doi={10.1147/rd.276.0577}, ISSN={0018-8646}, month={Nov}, } Best, -- Marcin Borkowski http://mbork.pl