elisp:数字不能大于(expt 2 60)?
elisp: number can't get greater than (expt 2 60)?
在之前的 post 中,someone 显示您可以在 elisp 中表达任何数字,因为它会自动切换到 big_nums。
但是当我调用 (setq long_max (expt 2 60))
时,我得到
1152921504606846976
当我调用 (setq long_max (expt 2 61))
时,我得到
-2305843009213693952
当我调用 (setq long_max (expt 2 62))
时,我得到
0
什么给了?我发现上面 link 中的数字 32768 32768 也得到了 0。为什么我没有得到相同大小的整数。对于上下文,我将 Spacemacs 与 Org-Mode
结合使用
谢谢!
默认情况下,Emacs Lisp 没有 bignums,正如这里的回答:bignum in emacs/elisp(它也引用了强大的 calc
包)。
您看到的 wrap-around 行为是因为计算是使用模块化算法进行的:请参阅 https://www.gnu.org/software/emacs/manual/html_node/elisp/Integer-Basics.html#Integer-Basics。
实际上在 post 你提到 Why in LISP , there is no limitation for number?,@Kaz 给出的答案就是你要找的。
(搜索 "Emacs Lisp packs integers into")
在之前的 post 中,someone 显示您可以在 elisp 中表达任何数字,因为它会自动切换到 big_nums。
但是当我调用 (setq long_max (expt 2 60))
时,我得到
1152921504606846976
当我调用 (setq long_max (expt 2 61))
时,我得到
-2305843009213693952
当我调用 (setq long_max (expt 2 62))
时,我得到
0
什么给了?我发现上面 link 中的数字 32768 32768 也得到了 0。为什么我没有得到相同大小的整数。对于上下文,我将 Spacemacs 与 Org-Mode
结合使用谢谢!
默认情况下,Emacs Lisp 没有 bignums,正如这里的回答:bignum in emacs/elisp(它也引用了强大的 calc
包)。
您看到的 wrap-around 行为是因为计算是使用模块化算法进行的:请参阅 https://www.gnu.org/software/emacs/manual/html_node/elisp/Integer-Basics.html#Integer-Basics。
实际上在 post 你提到 Why in LISP , there is no limitation for number?,@Kaz 给出的答案就是你要找的。 (搜索 "Emacs Lisp packs integers into")