help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculator: no exponent, full number ?


From: Marcin Borkowski
Subject: Re: Calculator: no exponent, full number ?
Date: Thu, 06 Jun 2019 17:47:44 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

On 2019-06-06, at 01:47, Emanuel Berg via help-gnu-emacs 
<help-gnu-emacs@gnu.org> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]