0

In a previous post, someone shows that you can express any number in elisp because it switchs over to big_nums automatically.

But when I call (setq long_max (expt 2 60)), I get

1152921504606846976

And when I call (setq long_max (expt 2 61)), I get

-2305843009213693952

And when I call (setq long_max (expt 2 62)), I get

0

What gives? I found that the numbers from the link above, 32768 32768, get me 0 as well. Why am I not getting the same sized integers. For context, I am using Spacemacs with Org-Mode

Thanks!

Community
  • 1
  • 1
Cameron
  • 2,805
  • 3
  • 31
  • 45
  • 3
    The previous post you reference was not about elisp, but about other dialects of Lisp, probably Common Lisp, which does have bignums (and rationals, and complex numbers). Elisp is rather rudimentary by the standard of more modern Lisps (even by the standard of Lisps around when it was designed in fact). –  Jan 20 '17 at 22:41

2 Answers2

2

Emacs Lisp does not have bignums by default, as answered here: bignum in emacs/elisp (which also references the powerful calc packages).

The wrap-around behavior you see is because computation is made using modular arithmetic: see https://www.gnu.org/software/emacs/manual/html_node/elisp/Integer-Basics.html#Integer-Basics.

Community
  • 1
  • 1
coredump
  • 37,664
  • 5
  • 43
  • 77
1

actually in the post you mentioned Why in LISP , there is no limitation for number?, answer given by @Kaz is what you are looking for. (search for "Emacs Lisp packs integers into")

Community
  • 1
  • 1
rsm
  • 2,530
  • 4
  • 26
  • 33