在 Perl 中对非常大的数字执行数学运算 [英] Performing math operations on very large numbers in Perl

查看:62
本文介绍了在 Perl 中对非常大的数字执行数学运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个案例,数据文件中的某些值有 64 位环绕,这使得它们非常大,例如,18446744073709551608.

I have a case where some values in a data file have 64 bit wrap around which makes them very large, like, 18446744073709551608.

所以我必须对 2^64 进行减法运算.我尝试使用简单的

So I have to perform a subtraction from 2^64. I tried this using the simple

2^64 - 18446744073709551608

但我猜这个数字太大了,没有得到实际的答案 8. 我需要做什么来执行这个减法.

But I guess this number is too large and don't get the actual answer 8. What do I need to do to perform this substraction.

推荐答案

查看 bignum 编译指示:

Check out the bignum pragma:

use bignum;

print 2**64 - 18446744073709551608;

这应该正确打印8.

这篇关于在 Perl 中对非常大的数字执行数学运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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