什么基础会更适合我的BigInteger库? [英] What base would be more appropriate for my BigInteger library?

查看:199
本文介绍了什么基础会更适合我的BigInteger库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C ++中开发了自己的BigInteger库,为了教导目的,最初我使用了base 10,它适用于加,减和乘法,但是对于一些算法,如指数,模幂运算和除法,更合适的使用基础2。

I have developed my own BigInteger library in C++, for didactic purpose, initially I have used base 10 and it works fine for add, subtract and multiply, but for some algorithms such as exponentiation, modular exponentiation and division it appears to be more appropriate use base 2.

我想从头开始重新启动我的项目,我会知道你认为什么基础更充分,为什么?提前感谢!

I am thinking restart my project from scratch and I would know what base do you think is more adequate and why?. Thanks in advance!

推荐答案

如果你查看大多数BigNum类型库,你会看到他们是建立在现有的 SmallNum数据类型。这些SmallNum数据类型(short,int,long,float,double,...)是二进制的,因为太多原因要计数。如果使用一个向量(例如) unsigned int s,你的代码将会快得多(更多,更快,更快! 。

If you look at most BigNum type libraries you will see that they are built on top of the existing "SmallNum" data types. These "SmallNum" data types (short, int, long, float, double, ...) are in binary for too many reasons to count. Rather than a vector of base 10 digits, your code will be much faster (much, much, much faster!) if work with a vector of (for example) unsigned ints.

这是性能计数的地方之一。假设你使用BigNum包来解决一个可以在不借助BigNums的情况下解决的问题。即使是最好的BigNum库将会比一个简单的非BigNum方法慢得多(慢得多)。如果您尝试解决超出标准表示的限制的问题,那么性能损失会使情况更糟。

This is one of those places where performance does count. Suppose you use a BigNum package to solve a problem that could be solved without resorting to BigNums. Even the best BigNum library will be much slower (much, much slower) than will a simplistic, non-BigNum approach. If you try to solve a problem that is beyond the bounds of the standard representations that performance penalty will make things even worse.

克服这种内在惩罚的最好办法是尽可能多地利用内置类型的优点。

The best way to overcome this inherent penalty is to take as much advantage of the builtin types as you possibly can.

这篇关于什么基础会更适合我的BigInteger库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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