コンテンツにスキップ

任意精度演算

出典: フリー百科事典『ウィキペディア(Wikipedia)』
多倍長整数から転送)

[1]

[]


0.122

[2] ( bigint )  bignum 



使

[]


 a + b 3 3a + 3b 

[]


使使 使

使[3]調使

使4999900001665535 1 65535 

3264使使 (L + R) / 2  L + R 

LISPREXXPythonPerlRuby 

[]


12使



使

  

 

  Schönhage-Strassen-Algorithmus  1

[]


使

11*2(1*2)*3((1*2)*3)*4 使
program Factorial ;
  type natural = range 1..integer.last of integer ;
  type radical = range 2..integer.last of integer ;
  type COLUMNS_TYPE = record
    const MAX_LENGTH : natural = 1000 ; (* 十分な桁数を上限とする *)
    values : array [1:MAX_LENGTH] of natural ;
    length : natural ;
    radix : radical ;
    end ;
  
  procedure factorial (const n : natural, var columns : COLUMNS_TYPE) ;
    begin
    columns.length := 1 ;
    columns.values [columns.length] := 1 ; (* 最初は乗法の単位元 1 を設定する *)
    var carry : integer = 0 ;              (* 下の位からの桁上り *)
    for var ci := 1 to columns.length do   (* 桁ごとにループ *)
      begin
      const c = columns.values [ci] * n + carry ;  (* この桁の数との乗算と下の位からの桁上りの和 *)
      columns.values [ci] := c mod columns.radix ; (* 積の下位桁 *)
      carry := c div columns.radix ;               (* 積の上位桁、上の位への桁上り *)
      end ;
    while 0 < carry do
      begin
      if COLUMNS_TYPE.MAX_LENGTH <= columns.length then
        raise OverflowError ;
      columns.length := columns.length + 1 ;                       (* 桁を増やす *)
      columns.values [columns.length] := carry mod columns.radix ; (* 実際に格納 *)
      carry := carry div columns.radix ;                           (* 次の位への桁上り *)
      (* n が基数より大きければ、もう1桁必要になることがある。 *)
      end
    end ;
  
  procedure writeColumns (var column : COLUMNS_TYPE) ;
    begin
    if 36 < columns.radix then raise OutOfRangeError ;
    const DIGITS : array of character = ['0'..'9','A'..'Z'] ; (* 36進法まで対応可能 *)
    for var ci := columns.length downto 1 do
      write (DIGITS [columns.values [ci]]) ; (* 大きい桁から表示 *)
    end ;
  
  begin
  for var n := 1 to 35 do
    begin
    var columns : COLUMNS_TYPE ;
    columns.radix := 10 ; (* 10進法 *)
    factorial (n, columns) ;
    writeColumns (columns) ; writeln (' = !', n)
    end
  end.

00便0101

10 c1101632767 n10 n 3200  n n
                                                 コンピュータでの数値表現の範囲
                                        1 =  1!
                                        2 =  2!
                                        6 =  3!
                                       24 =  4!
                                      120 =  5!   8ビット符号なし  
                                      720 =  6!
                                     5040 =  7!
                                    40320 =  8!  16ビット符号なし
                                   362880 =  9!   
                                  3628800 = 10!   
                                 39916800 = 11!   
                                479001600 = 12!  32ビット符号なし
                               6227020800 = 13!   
                              87178291200 = 14!   
                            1307674368000 = 15!   
                           20922789888000 = 16!   
                          355687428096000 = 17!   
                         6402373705728000 = 18!   
                       121645100408832000 = 19!   
                      2432902008176640000 = 20!  64ビット符号なし
                     51090942171709440000 = 21!   
                   1124000727777607680000 = 22!   
                  25852016738884976640000 = 23!   
                 620448401733239439360000 = 24!   
               15511210043330985984000000 = 25!   
              403291461126605635584000000 = 26!   
            10888869450418352160768000000 = 27!   
           304888344611713860501504000000 = 28!   
          8841761993739701954543616000000 = 29!   
        265252859812191058636308480000000 = 30!   
       8222838654177922817725562880000000 = 31!
     263130836933693530167218012160000000 = 32!
    8683317618811886495518194401280000000 = 33!
  295232799039604140847618609643520000000 = 34! 128ビット符号なし
10333147966386144929666651337523200000000 = 35!

1003210,000使610000 mod  div  IBM 1130 1632216655361616 mod  div 

C FORTRAN EQUIVALENCE PL/1  OVERLAY使

1 (radix - 1)2 + carry carry  (base - 1) IBM 1130 3216161665536 4,294,901,760 32 3232 使32使64?

163264使 i j2使 

[]


1959 IBM 1620 1620 61620FORTRAN101620使使

IBM  IBM 702 511Maclisp 1980VAX  IBM  REXX 

[]

[]


Mathematica Mathematica GMP

PARI/GP  

bc - Unix

Maxima  Common Lisp 

Ultra Fractal  

Fractint   FLOSS 

Virtual Calc 2000  /Windows

Calc  CLGPL2

SpeedCrunch  

TTCalc  TTMath使

Big Online Calculator  TTMath使

LM   10^100000000

[]








パッケージ/ライブラリ名 数値型 言語 ライセンス
apfloat 十進浮動小数点、整数、有理数複素数 JavaC++ LGPLおよびフリーウェア
ARPREC and MPFUN 整数、二進浮動小数点数、複素二進浮動小数点数 C++、バインディングは C++FORTRAN BSD
Base One Number Class 十進浮動小数点数 C++ 有償
bbnum library 整数、浮動小数点数 アセンブリ言語、C++ 改訂BSD
phpseclib 十進浮動小数点数 PHP LGPL
BigDigits 自然数 C言語 フリーウェア[1]
Class Library for Numbers(CLN) 整数、有理数複素数 C言語、C++ GPL
Computable Real Numbers 実数 Common Lisp
IMSL C言語 商用
decNumber 十進数 C言語 ICU licence(MIT Licence[2]
FMLIB 浮動小数点数 FORTRAN
GNU Multi-Precision Library(および MPFR英語版 整数、有理数、浮動小数点数 C言語、C++、他[4] LGPL
GNU Multi-Precision Library for .NET 整数 C#.NET LGPL
GNU Multi-Precision Library for Eiffel 整数、実数 Eiffel LGPL
HugeCalc 整数 C++、アセンブリ言語 有償
IMath 整数、有理数 C言語 フリーウェア
IntX 整数 C#.NET 改訂BSD
JScience LargeInteger 整数 Java
LibTomMath 整数 C言語、C++ パブリックドメイン
LiDIA 整数 C言語、C++ 非商用利用については無料
MAPM 整数、十進浮動小数点数 C言語(バインディングは C++Lua フリーウェア
MIRACL 整数、有理数 C言語、C++ 非商用利用については無料
MPI 整数 C言語 LGPL
MPArith 整数、浮動小数点数、有理数 Borland PascalDelphi zlib
mpmath 浮動小数点数、複素浮動小数点数 Python 改訂BSD
NTL 整数 C言語、C++ GPL
OpenSSL 整数 C言語 OpenSSL+SSLeay
TTMath library 整数、二進浮動小数点数 アセンブリ言語、C++ 改訂BSD
vecLib.framework 整数 C言語 プロプライエタリ
W3b.Sine 十進浮動小数点数 C#.NET 改訂BSD
Boost.Multiprecision 整数、浮動小数点 C++ Boost Software License

[]




Common Lisp  

dc  POSIX

Erlang  

Haskell  

Java  java.math.BigInteger java.math.BigDecimal 

.NET  System.Numerics.BigInteger :4

OCaml  Num

Perl  bigintbignumMath::BitInt, Math::BitFloat

Python   int3.xlong2.x Decimal 

REXX  Open Object Rexx  NetRexx 

Ruby   Bignum  BigDecimal 

Scheme  R5RSR6RS

Scala  BigInt .

Smalltalk  Squeak 

JavaScript  bigint 

[]



(一)^ : arbitrary-precision arithmetic

(二)^ : bignum arithmetic

(三)^ R.K. Pathria A Statistical Study of the Randomness amongst the first 10,000 Digits of Pi1962Mathematics of Computation 16N77-80pp 188-97 77100028Such an extreme pattern is dangerous even if diluted by one of its neighbouring blocks

(四)^ GMPY

参考文献[編集]

  • Knuth, Donald, The Art of Computer Programming, ISBN 0-201-89684-2, Volume 2: Seminumerical Algorithms, Section 4.3.1: The Classical Algorithms
  • Implementing Multiple-Precision Arithmetic, Part 1
  • Nikolaevskaya et al. : "Programming with Multiple Precision", Springer-Verlag, ISBN 978-3-642-25672-1, e-ISBN 978-3-642-25673-8 (2012).
  • 幸谷智紀 : 多倍長精度数値計算, 森北出版, ISBN 978-4-627-85491-8 (2019年11月)。
  • Fürer, M. : "Faster Integer Multiplication", SIAM J. Comput., Volume 39 Issue 3, 2009, pages 979–1005.
  • Harvey, D. and van der Hoeven, J. : "Integer Multiplication in Time O(nlogn)".
  • Karatsuba, A. : "The Complexity of Computations", Proceedings of the Steklov Institute of Mathematics, Volume 211, 1995, pages 169–183.
  • Schönhage, A. and Strassen, V. : "Schnelle Multiplikation grosser Zahlen", Computing, Volume 7, Issue 3–4, September 1971, pages 281–292.
  • Erica Klarreich : "Multiplication Hits the Speed Limit", Communications of the ACM, January 2020, Vol. 63 No. 1, Pages 11-13. doi=10.1145/3371387.

関連項目[編集]