From: Emanuel Berg via help-gnu-emacs <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Cc: Ingemar Holmgren <dag.h@hotmail.se>
Subject: Re: Calculator: no exponent, full number ?
Date: Thu, 06 Jun 2019 18:50:55 +0200 [thread overview]
Message-ID: <86wohyodxs.fsf@zoho.eu> (raw)
In-Reply-To: 875zpibtr3.fsf@mbork.pl
Marcin Borkowski 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.
Well, first let it be known that Marcin is
a professional mathematician, famous for his
remarkable calculations. That said, the above
comment is on the computer side of things,
right? In the math world, what would happen is
just a very large triangle, again - right?
Assuming integers, how large can they be in
Emacs Lisp? Eval us:
most-positive-fixnum ; 536870911
"Typical values are 2**29 − 1 on 32-bit and
2**61 − 1 on 64-bit platforms." [1]
most-negative-fixnum ; -536870912
"Typical values are −2**29 on 32-bit
and −2**61 on 64-bit platforms." [1]
How do you know if your "platform"
(i.e. kernel?) is 32- or 64-bit?
Tricky, but here is an incomplete guide from
the systems I have access to:
Debian Intel: uname -m; i686 -> 32-bit, x86_64 -> 64
OpenBSD: uname -m; amd64 -> 64 (same type as x86-64 BTW)
RPi3 Raspbian: uname -m; armv7l -> 32
SunOS/Solaris: 'isainfo -kv' tells you
Also remember that you can have 64 HW but still
a 32 Linux kernel - but probably not the other
way around :)) (?)
Otherwise you can use Emacs to find out!
most-positive-fixnum ; 536870911
then compute 2**29 - 1:
# /bin/zsh
$ echo $(( 2**29 − 1 ))
536870911
so yes, it checks out for my RPi3 :)
> Also, it is slow because of the need to
> compute square roots. Interestingly, there
> exists a clever algorithm that does not have
> these problems.
Why don't you post it in Elisp to prove my
point one can use Elisp for math, even advanced
math! <3
> It is used (among others) in Donald Knuth's
> METAFONT. The algorithm is described in the
> paper (using Emanuel's favorite format;-)):
That's true, I frekking *love* Biblatex! [2]
> @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},
> }
Only I keep mine much neater :)
@book{land-of-lisp,
author = {Conrad Barski},
isbn = 1593272812,
publisher = {No Starch},
title = {Land of Lisp},
year = 2010
}
@book{lispcraft,
author = {Robert Wilensky},
isbn = 0393954420,
publisher = {Norton},
title = {LISPcraft},
year = 1984
}
%% [3]
[1] (info "(elisp) Integer Basics")
[2] https://dataswamp.org/~incal/emacs-init/my-bibtex.el
[3] https://dataswamp.org/~incal//books/books.bib
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
next prev parent reply other threads:[~2019-06-06 16:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-04 19:43 Calculator: no exponent, full number ? jonetsu
2019-06-04 22:42 ` Emanuel Berg via help-gnu-emacs
2019-06-05 11:15 ` Emanuel Berg via help-gnu-emacs
2019-06-05 4:11 ` Marcin Borkowski
2019-06-05 4:26 ` Emanuel Berg via help-gnu-emacs
2019-06-05 13:53 ` jonetsu
2019-06-05 23:47 ` Emanuel Berg via help-gnu-emacs
2019-06-06 14:50 ` Nick Dokos
2019-06-26 4:09 ` Xavier Maillard
2019-06-06 15:47 ` Marcin Borkowski
2019-06-06 16:50 ` Emanuel Berg via help-gnu-emacs [this message]
2019-06-06 17:04 ` tomas
2019-06-06 17:11 ` Emanuel Berg via help-gnu-emacs
2019-06-06 17:25 ` tomas
2019-06-07 19:36 ` Marcin Borkowski
2019-06-14 12:20 ` Van L
2019-06-14 13:26 ` Robert Pluim
2019-06-14 19:57 ` Stefan Monnier
2019-06-15 9:29 ` Van L
2019-06-14 19:43 ` Emanuel Berg via help-gnu-emacs
2019-06-15 9:23 ` Van L
-- strict thread matches above, loose matches on Subject: below --
2019-06-06 17:28 Joe Trivers via help-gnu-emacs
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86wohyodxs.fsf@zoho.eu \
--to=help-gnu-emacs@gnu.org \
--cc=dag.h@hotmail.se \
--cc=moasenwood@zoho.eu \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.