最好的跨平台(便携式)任意precision数学库 [英] The best cross platform (portable) arbitrary precision math library

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

问题描述

我在寻找一个好的任意precision数学C或C ++库。能否请您给我一些意见/建议吗?

主要的要求:


  1. 必须的处理任意大整数(我的主要兴趣是整数)。在你不知道什么擅自字大手段的情况下,想象像100000! (100000阶乘)。

  2. 的precision 必须在不需要将被初始化存储库/对象创建过程中指定。在precision应只有由系统的可用资源的制约。

  3. 应该的利用平台的全部功能,并且应该在本地处理的小的数字。也就是说,一个64位的平台上,在计算2 ^ 33 + 2 ^ 32应该使用可用的64位CPU的指令。库不应以同样的方式计算出这个,因为它有2 ^ 66 + 2 ^ 65在同一平台上一样。

  4. 必须的手柄加(+),减( - ),乘(*),整数除法(/),余(%),电力(**),递增(++) ,减( - ),GCD(),阶乘(),和其他普通的整数算术运算效率。能够处理像开方函数()(平方根),日志()(对数)不产生整数结果是一个加号。能够处理符号计算,甚至更好。

下面是什么,我发现迄今:


  1. 的Java 的BigInteger 的BigDecimal 类:我一直在使用这些至今。我已阅读源$ C ​​$ C,但我不明白下面数学。这可能是基于我从来就没有学到的理论/算法。

  2. 内置的整数类型或在核心库的 公元前 / <一href=\"http://docs.python.org/release/3.1.2/reference/lexical_analysis.html#integer-literals\">Python / 红宝石 / 哈斯克尔 / Lisp语言 / 二郎山 / 的OCaml / PHP /其他语言:我曾经使用过其中的一些,但我对他们所使用的库中没有的想法,或者哪一种他们正在使用实施

我已经知道:


  1. 使用 字符 为十进制数,以及A 的char * 作为一个十进制字符串,做计算使用一个for循环的位数。

  2. 使用 INT (或 长整型 很长很长 )作为一个基本的单位和它的一个数组作为一个任意长整数,并做使用一个for循环中的元素计算。

  3. 使用整型来存储一个十进制数(或数位)为 BCD(二进制 - codeD十进制)

  4. 布斯乘法算法

我不知道的:



  1. 打印十进制上述不使用幼稚的方法二进制数组。一个幼稚方法的实施例:(1)从最低添加比特到最高:1,2,4,8,16,32,...(2)使用的字符* 的字符串上述存储中间小数结果)。

我AP preciate:


  1. 好比较的 GMP MPFR decNumber (或其他图书馆那在您看来,好)。

  2. 书上/文章,我应该读
  3. 好建议。例如,数字上的未幼稚的二进制怎么转换成十进制算法的根基是好的。这篇文章的 二进制到十进制的转换在有限precision 由Douglas W. Jones是一篇好文章的例子。

  4. 任何帮助。

不要的回答这个问题,如果:


  1. 您觉得使用 双击 (或 长双 长长的双 )可以很容易地解决这个问题。如果你这样认为,那就意味着你不明白正在讨论的问题。


解决方案

GMP是热门选择。佳乐Smalltalk中有一个非常好的图书馆,但它是写在Smalltalk。

您询问相关书籍或文章。大数的最棘手的部分是长除法。我建议泊·派克·汉森的论文多长司再访:雷区介绍

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

The primary requirements:

  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).
  2. The precision MUST NOT NEED to be specified during library initialization / object creation. The precision should ONLY be constrained by the available resources of the system.
  3. 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.
  4. It MUST handle addition (+), subtraction (-), multiplication (*), integer division (/), remainder (%), power (**), increment (++), decrement (--), gcd(), factorial(), and other common integer arithmetic calculations efficiently. Ability to handle functions like sqrt() (square root), log() (logarithm) that do not produce integer results is a plus. Ability to handle symbolic computations is even better.

Here are what I found so far:

  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 / algorithms that I have never learnt.
  2. The built-in integer type or in core libraries of bc / Python / Ruby / Haskell / Lisp / Erlang / OCaml / PHP / some other languages: I have ever used some of these, but I have no idea on which library they are using, or which kind of implementation they are using.

What I have already known:

  1. Using a char as a decimal digit, and a char* as a decimal string and do calculations on the digits using a for-loop.
  2. Using an int (or a long int, or a long long) as a basic "unit" and an array of it as an arbitrary long integer, and do calculations on the elements using a for-loop.
  3. Using an integer type to store a decimal digit (or a few digits) as BCD (Binary-coded decimal).
  4. Booth's multiplication algorithm

What I don't know:

  1. Printing the binary array mentioned above in decimal without using naive methods. 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).

What I appreciate:

  1. Good comparisons on GMP, MPFR, decNumber (or other libraries that are good in your opinion).
  2. Good suggestions on books / articles that I should read. For example, an illustration with figures on how an un-naive binary to decimal conversion algorithm works is good. The article "Binary to Decimal Conversion in Limited Precision" by Douglas W. Jones is an example of a good article.
  3. Any help.

Please DO NOT answer this question if:

  1. you think using a double (or a long double, or a long long double) can solve this problem easily. If you do think so, it means that you don't understand the issue under discussion.

解决方案

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

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.

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

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