programing

What are the best (portable) cross-platform arbitrary-precision math libraries?

itsource 2022. 7. 2. 23:01
반응형

What are the best (portable) cross-platform arbitrary-precision math libraries?

I’m looking for a good arbitrary precision math library in C or C++. Could you please give me some advices or 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 or 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 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'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.

  2. 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. 사용.char10진수 및char*10진수 문자열의 경우 및 숫자 계산을 수행합니다.for-루프

  2. 사용.int(또는long int, 또는long long기본 "단위" 및 해당 유형의 배열을 임의의 긴 정수로 하며, 다음 값을 사용하여 요소에 대한 계산을 수행합니다.for-루프

  3. 정수 유형을 사용하여 10진수(또는 몇 자리)를 BCD(Binary-coded 10진수)로 저장합니다.

  4. 부스의 곱셈 알고리즘이요

내가 모르는 것:

  1. 순진한 방법을 사용하지 않고 위에서 설명한 바이너리 배열을 10진수로 인쇄합니다.순진한 방법의 예: (1) 최하위부터 최고위까지 비트를 추가합니다.1, 2, 4, 8, 16, 32, … (2)는 a를 사용합니다.char*-string을 지정하면 중간 소수점 결과를 저장할 수 있습니다).

감사한 점:

  1. GMP, MPFR, dec Number(또는 고객의 생각에 적합한 기타 라이브러리)에 대한 적절한 비교.

  2. 내가 읽어야 할 책과 기사에 대한 좋은 제안.예를 들어, 비네이티브 바이너리에서 10진수로의 변환 알고리즘이 어떻게 기능하는지에 대한 그림이 있는 그림이 좋습니다.Douglas W의 "제한정밀도의 바이너리에서 10진수 변환" 기사.존스는 좋은 글의 한 예이다.

  3. 일반적인 도움입니다.

이 질문에 대답하지 마십시오.double(또는long double, 또는long long double)는 이 문제를 쉽게 해결할 수 있습니다.그렇게 생각한다면 문제의 문제를 이해하지 못한 것입니다.

GMP가 인기 있는 선택입니다.스퀵 스몰톡은 아주 좋은 도서관을 가지고 있지만 스몰톡으로 쓰여 있다.

관련 서적이나 기사를 요청하셨습니다.Bignums의 까다로운 부분은 긴 분할이다.나는 Per Brinch Hansen의 Multiple-Length Division Revisited: 지뢰밭 관광을 추천한다.

개인 및 상업용 무료 템플리트 헤더 전용 라이브러리인 TMath를 참조하십시오.

전반적으로 가장 빠른 범용 임의 정밀 라이브러리는 GMP입니다. 부동 소수점 값으로 작업하려면 MPFR 라이브러리를 참조하십시오.MPFR은 GMP를 기반으로 합니다.

다른 언어의 네이티브 임의 정밀도 지원과 관련하여 Python은 라이센스, 코드 크기 및 코드 이식성 이유로 자체 구현을 사용합니다.GMPY 모듈을 통해 Python은 GMP 라이브러리에 액세스할 수 있습니다.

파리는요?톱 GMP를 기반으로 구축되어 있으며, 여러분이 필요로 하는 수론 연산에 관한 다른 모든 장점(및 많은 상징적 연산)을 제공합니다.

나는 임의의 정밀 산술 라이브러리를 서로 비교한 적은 없지만, 어느 정도 GMP에 균등하게 정착한 것처럼 보이는 사람들이다.그것은 GHC Haskell과 GNU Guile Scheme의 임의의 정밀 정수는 모두 GMP를 사용하여 구현되며, 언어 슈우 벤치마크에서 피디짓의 가장 빠른 구현이다.tout은 GMP를 기반으로 합니다.

언급URL : https://stackoverflow.com/questions/2568446/what-are-the-best-portable-cross-platform-arbitrary-precision-math-libraries

반응형