[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calculator: no exponent, full number ?
From: |
Emanuel Berg |
Subject: |
Re: Calculator: no exponent, full number ? |
Date: |
Thu, 06 Jun 2019 18:50:55 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
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
- Calculator: no exponent, full number ?, jonetsu, 2019/06/04
- Re: Calculator: no exponent, full number ?, Emanuel Berg, 2019/06/04
- Re: Calculator: no exponent, full number ?, Marcin Borkowski, 2019/06/05
- Re: Calculator: no exponent, full number ?, Emanuel Berg, 2019/06/05
- Re: Calculator: no exponent, full number ?, jonetsu, 2019/06/05
- Re: Calculator: no exponent, full number ?, Marcin Borkowski, 2019/06/06
- Re: Calculator: no exponent, full number ?,
Emanuel Berg <=
- Re: Calculator: no exponent, full number ?, tomas, 2019/06/06
- Re: Calculator: no exponent, full number ?, Emanuel Berg, 2019/06/06
- Re: Calculator: no exponent, full number ?, tomas, 2019/06/06
- Re: Calculator: no exponent, full number ?, Marcin Borkowski, 2019/06/07
Re: Calculator: no exponent, full number ?, Van L, 2019/06/14
Re: Calculator: no exponent, full number ?, Emanuel Berg, 2019/06/14
Re: Calculator: no exponent, full number ?, Van L, 2019/06/15