如何在Perl中使用任意长度的整数? [英] How can I use arbitrary length integers in Perl?

查看:166
本文介绍了如何在Perl中使用任意长度的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中是否有任何标准方法可以使用任意长度的整数?我正在研究为测试生成x64程序集的代码,我厌倦了一次操作32位。

Is there any standard way to use integers of arbitrary length in Perl? I am working on code that generates x64 assembly for tests, and I'm tired of manipulating 32 bits at a time.

我正在使用Perl 5.10.0,for这是值得的。

I'm using Perl 5.10.0, for what it's worth.

推荐答案

如果你只想使用大整数,你可以使用 bigint ,您可以将其范围转换为文件:

If you only want to use big integers, you can use the bigint, which you can scope to a file:

 use bigint;

或仅限范围:

 {
 use bigint;
 ...;
 }

如果你需要大的浮点数和大整数,你可以使用 bignum pragma以同样的方式。无论哪种方式,这些都会稍微降低你的程序速度(或者如果你做了大量的数学运算,那么你的程序会很明显),所以你应该只将它们用于你真正需要它们的部分。但是,更快并不比正确更好。 :)

If you need big floating point numbers as well as big integers, you can use the bignum pragma in the same way. Either way, these will slow down your program slightly (or significantly if you are doing a lot of math), so you should only use them for the parts where you really need them. However, faster isn't better than correct. :)

如果你想非常精确地控制使用 big * 数学的数字,你可以使用底层实现它们并自己创建对象的类,而不是将 big * 语义应用于所有内容。看看 Math :: Big * 模块。

If you want very precise control over which numbers use the big* math, you can use the underlying classes that implement them and create objects yourself rather than applying the big* semantics to everything. Look that Math::Big* modules.

我在掌握Perl ,因为现在计算机太快,使用阶乘作为慢速功能,我们还添加了一个关于大的部分将它编号为即将发布的有效的Perl编程,第2版

I talk about this more in the Benchmarking chapter of Mastering Perl since computers are too fast nowadays to use a factorial as a slow function, and we also added a section on big numbers it to the upcoming Effective Perl Programming, 2nd Edition.

这篇关于如何在Perl中使用任意长度的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆