非常大的整数 [英] very large integers

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

问题描述

如果您正在设计一个用C ++表示非常大的整数的类,

什么样的内部表示最好?

If you were designing a class to represent very large integers in C++,
what kind of internal representation would be best?

推荐答案

* bo *@coolgroups.com

如果您正在设计一个用C ++表示非常大的整数的类,

什么样的内部表示最好?
If you were designing a class to represent very large integers in C++,
what kind of internal representation would be best?



取决于。但如果你想知道你可能最好使用现有的免费大整数库之一来获得



-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

答:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?

Depends. But if you''re wondering about that you''re probably best off
using one of the existing, free large integer libraries.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


bob写道:
bob wrote:

如果您正在设计一个用C ++表示非常大的整数的类,

什么样的内部表示最好?
If you were designing a class to represent very large integers in C++,
what kind of internal representation would be best?



vector< int> ;?


哦,我可以使用 http://www.google.com/codesearch 这个!


正在搜索 ; bigint lang:c ++ vector.int",没有引号,我明白了:

http://www.cs.hmc.edu/courses/mostRe...k/cs70ass2.tgz

class BigInt {

...

vector< intchunks_; // BigInt的价值。


所以看起来他们像我建议的那样使用向量作为计数

算法,对待每个int作为符号,基数为20亿。


问题:这是否是最优的,每个向量'对

遍历速度的保证,vs速度推回等等? std :: list表现更好

或更差?


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!

vector<int>?

Ooh, I can use http://www.google.com/codesearch for this one!

Searching for "bigint lang:c++ vector.int", without the quotes, I get this:

http://www.cs.hmc.edu/courses/mostRe...k/cs70ass2.tgz

class BigInt {
...
vector<intchunks_; // Value of the BigInt.

So it looks like they used the vector, like I suggested, as a "counting"
algorithm, treating each int as a symbol, in base 2-billion.

Question: Is this optimal, per vector''s guarantees on the speed of
traversal, vs speed pushing back and such? Would a std::list perform better
or worse?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


Phlip写道:
Phlip wrote:

bob写道:
bob wrote:

>如果您正在设计一个用C ++表示非常大的整数的类,那么什么样的内部表示最好?
>If you were designing a class to represent very large integers in C++,
what kind of internal representation would be best?



vector< int>?


vector<int>?



vector< unsignedis好多了。用

签名类型编写半数值算法会产生很大的麻烦。只要问任何人用Java实现

大整数。


- Pete


作者标准C ++库扩展:教程和

参考。有关本书的更多信息,请参阅
www.petebecker.com/tr1book


这篇关于非常大的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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