オーバーフローしないプログラミング言語

Development

Twitter プライベートユーザーから「オーバーフローしない言語が Python 以外にあるか調べて記事にして(適当」と来たので。

numbers

Python の整数型

Python は、整数型の int (Python 3)、long (Python 2) は、桁数がメモリ容量にのみ制限される多倍長整数のようです。

任意精度演算をサポートする言語

他の言語も調べてみます。Python は、組み込みの整数型が、任意精度演算をサポートしています。ここでは、単に標準で任意精度演算をサポートするプログラミング言語を挙げます(つまり、オーバーフローする型を含む言語も挙げています)。

Wikipedia 任意精度演算 にまとめてあったので、それを参照。

組み込みまたは標準ライブラリの形式で任意精度演算をサポートするプログラミング言語を以下に挙げる。

  • Common Lisp — 多倍長整数、有理数、複素数をサポート
  • dc — POSIXの電卓ユーティリティ
  • Erlang — 組み込みの整数型が多倍長整数となっている。
  • Haskell — 組み込みの整数型が多倍長整数となっている。
  • Java — java.math.BigInteger クラス(整数)、java.math.BigDecimal クラス(十進整数)
  • .NET — System.Numerics.BigInteger 構造体(整数:4以降)
  • OCaml — Numライブラリで多倍長整数と有理数をサポート
  • Perl — bigintプラグマを指定することによりスコープ単位で多倍長整数指定が可能。bignumプラグマにより多倍長浮動小数点指定。それぞれMath::BitInt, Math::BitFloatモジュールで実装されている。
  • Python — 組み込みの int(第3.x版)、long(第2.x版)という整数型が多倍長整数。標準ライブラリには Decimal クラスもあり、桁数を指定可能。
  • REXX — Open Object Rexx や NetRexx も同様。
  • Ruby — 組み込みの Bignum という整数型が多倍長整数。標準ライブラリには BigDecimal クラスがあり、桁数を指定可能。
  • Scheme — 任意精度の整数と有理数をサポート(R5RS では推奨、R6RS では必須)
  • Scala — BigInt クラス.
  • Smalltalk — Squeak などの各種処理系でサポート。

2015/12/27 時点の 任意精度演算 より。

さらに検索

Wikipedia 日本語ページでは以上ですが、英語の List of arbitrary-precision arithmetic software も見てみましょう。

Programming languages that supports arbitrary precision computations, either built-in, or in the standard library of the language:

  • Agda: the BigInt datatype on Epic backend implements arbitrary-precision arithmetic.
  • Common Lisp: The ANSI Common Lisp standard supports arbitrary precision integer, ratio and complex numbers.
  • C#: System.Numerics.BigInteger, from .NET Framework 4.0
  • ColdFusion: the built-in PrecisionEvaluate() function evaluates one or more string expressions, dynamically, from left to right, using BigDecimal precision arithmetic to calculate the values of arbitrary precision arithmetic expressions.
  • D: standard library module std.bigint
  • Dart: the built-in int datatype implements arbitrary-precision arithmetic.
  • Erlang: the built-in Integer datatype implements arbitrary-precision arithmetic.
  • Go: the standard library package math/big implements arbitrary-precision integers (Int type) and rational numbers (Rat type)
  • Haskell: the built-in Integer datatype implements arbitrary-precision arithmetic and the standard Data.Ratio module implements rational numbers.
  • Idris: the built-in Integer datatype implements arbitrary-precision arithmetic.
  • ISLISP: The ISO/IEC 13816:1997(E) ISLISP standard supports arbitrary precision integer numbers.
  • J: built-in extended precision
  • Java: Class java.math.BigInteger (integer), Class java.math.BigDecimal (decimal)
  • JavaScript: the gwt-math library provides an interface to java.math.BigDecimal, and libraries such as BigInt and Crunch support arbitrary-precision integers.
  • Julia: the built-in “BigFloat" and “BigInt" types provide arbitrary-precision floating point and integer arithmetic respectively.
  • OCaml: The Num library supports arbitrary-precision integers and rationals.
  • OpenLisp: supports arbitrary precision integer numbers.
  • Perl: The bignum and bigrat pragmas provide BigNum and BigRational support for Perl.
  • PHP: The BC Math module provides arbitrary precision mathemathics.
  • Pike: the built-in int type will silently change from machine-native integer to arbitrary precision as soon as the value exceeds the former’s capacity.
  • Python: the built-in int (3.x) / long (2.x) integer type is of arbitrary precision. The Decimal class in the standard library module decimal has user definable precision and limited mathematical operations (exponentiation, square root, etc. but no trigonometric functions). The Fraction class in the module fractions implements rational numbers. More extensive arbitrary precision floating point arithmetic is available with the third-party “mpmath" and “bigfloat" packages.
  • Racket: the built-in exact numbers are of arbitrary precision. Example: (expt 10 100) produces the expected (large) result. Exact numbers also include rationals, so (/ 3 4) produces 3/4.
  • Rexx: variants including Open Object Rexx and NetRexx
  • Ruby: the built-in Bignum integer type is of arbitrary precision. The BigDecimal class in the standard library module bigdecimal has user definable precision.
  • Scheme: R5RS encourages, and R6RS requires, that exact integers and exact rationals be of arbitrary precision.
  • Scala: Class BigInt and Class BigDecimal.
  • Seed7: bigInteger and bigRational.
  • Smalltalk: variants including Squeak, Smalltalk/X, GNU Smalltalk, Dolphin Smalltalk, etc.
  • Standard ML: The optional built-in IntInf structure implements the INTEGER signature and supports arbitrary-precision integers.
  • Wolfram Language, like Mathematica, employs GMP for approximate number computation.

2015/12/27 時点の List of arbitrary-precision arithmetic software より。

どひゃー、日本語記事の倍以上ですよ。英語版も参照するの大事ですね。

Development

Posted by jz5