最好的(便携式)跨平台任意精度数学库是什么? [英] What are the best (portable) cross-platform arbitrary-precision math libraries?

查看:73
本文介绍了最好的(便携式)跨平台任意精度数学库是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个使用C或C ++编写的良好的任意精度数学库.您能给我一些建议吗?

I’m looking for a good arbitrary precision math library in C or C++. Could you please give me some advices or suggestions?

主要要求:

  1. 必须处理任意大整数-我的主要兴趣是整数.如果您不知道任意大这个词是什么意思,请想象一下类似100000的东西!(阶乘为100000).

  1. It must handle arbitrarily big integers—my primary interest is on integers. In case that you don’t know what the word arbitrarily big means, imagine something like 100000! (the factorial of 100000).

在库初始化或对象创建期间不必指定精度 .精度应该受系统可用资源的限制.

The precision must not need to be specified during library initialization or object creation. The precision should only be constrained by the available resources of the system.

应充分利用平台的功能,并应本机处理小"数字.这意味着在64位平台上,计算(2 ^ 33 + 2 ^ 32)应该使用可用的64位CPU指令.库不应以与在同一平台上(2 ^ 66 + 2 ^ 65)相同的方式进行计算.

It should utilize the full power of the platform, and should handle "small" numbers natively. That means on a 64-bit platform, calculating (2^33 + 2^32) should use the available 64-bit CPU instructions. The library should not calculate this in the same way as it does with (2^66 + 2^65) on the same platform.

必须有效地处理加法( + ),减法(-),乘法( * ),整数除法(/),余数(),幂( ** ),增量( ++ ),减量(-),GCD,阶乘和其他常见的整数算术计算.能够处理不会产生整数结果的函数(例如平方根和对数)是一个加号.处理符号计算的能力甚至更好.

It must efficiently handle addition (+), subtraction (-), multiplication (*), integer division (/), remainder (%), power (**), increment (++), decrement (--), GCD, factorial, and other common integer arithmetic calculations. The ability to handle functions like square root and logarithm that do not produce integer results is a plus. The ability to handle symbolic computations is even better.

这是我到目前为止发现的东西:

Here are what I found so far:

  1. Java BigInteger

  1. Java's BigInteger and BigDecimal class: I have been using these so far. I have read the source code, but I don’t understand the math underneath. It may be based on theories and algorithms that I have never learnt.

内置整数类型或 Python Ruby Haskell Lisp Erlang OCaml PHP ,还有其他一些语言:我使用了其中一些语言,但是我不知道它们使用的是哪个库,或者使用的是哪种实现.

The built-in integer type or in core libraries of bc, Python, Ruby, Haskell, Lisp, Erlang, OCaml, PHP, some other languages: I have used some of these, but I have no idea which library they are using, or which kind of implementation they are using.

我所知道的:

  1. 使用 char 表示十进制数字,使用 char * 表示十进制字符串,并使用 for 循环对数字进行计算

  1. Using char for decimal digits and char* for decimal strings, and do calculations on the digits using a for-loop.

使用 int (或 long int long long )作为基本的单位"和该类型的数组作为任意长整数,并使用 for 循环对元素进行计算.

Using int (or long int, or long long) as a basic "unit" and an array of that type as an arbitrary long integer, and do calculations on the elements using a for-loop.

使用整数类型将小数位数(或几位数)存储为<​​strong>

Using an integer type to store a decimal digit (or a few digits) as BCD (Binary-coded decimal).

Booth的乘法算法 ./p>

我不知道的东西:

  1. 在不使用幼稚方法的情况下,以十进制打印上述二进制数组.一个朴素方法的示例:(1)从最低到最高的位相加:1,2,4,8,16,16,32,...(2)使用提到的 char * 字符串上面存储中间十进制结果).
  1. Printing the binary array mentioned above in decimal without using naive methods. An example of a naive method: (1) add the bits from the lowest to the highest: 1, 2, 4, 8, 16, 32, … (2) use a char*-string mentioned above to store the intermediate decimal results).

我的感激之情

  1. GMP MPFR

  1. Good comparisons on GMP, MPFR, decNumber (or other libraries that are good in your opinion).

关于我应该阅读的书籍和文章的好的建议.例如,用图例说明非幼稚二进制到十进制转换算法是如何工作的.文章" 以有限精度进行二进制到十进制的转换道格拉斯·W·琼斯(Douglas W.Jones)的《 》就是一篇好文章的例子.

Good suggestions on books and articles that I should read. For example, an illustration with figures on how a non-naive binary-to-decimal conversion algorithm works would be good. The article "Binary to Decimal Conversion in Limited Precision" by Douglas W. Jones is an example of a good article.

任何一般帮助.

如果您认为使用 double (或 long double ,或 long long double )可以轻松解决此问题.如果您这样认为,则说明您不了解所涉及的问题.

Please do not answer this question if you think that using double (or long double, or long long double) can solve this problem easily. If you do think so, you don’t understand the issue in question.

推荐答案

GMP是流行的选择.Squeak Smalltalk有一个非常不错的库,但是它是用Smalltalk编写的.

GMP is the popular choice. Squeak Smalltalk has a very nice library, but it's written in Smalltalk.

您要求提供相关的书籍或文章.bignums的棘手部分是长除法.我建议Per Brinch Hansen的论文重访多长度部门:雷场之旅

You asked for relevant books or articles. The tricky part of bignums is long division. I recommend Per Brinch Hansen's paper Multiple-Length Division Revisited: A Tour of the Minefield.

这篇关于最好的(便携式)跨平台任意精度数学库是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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