Extension:BCmath

From mediawiki.org
This page is a translated version of the page Extension:BCmath and the translation is 84% complete.
MediaWiki 拡張機能マニュアル
BCmath
リリースの状態: 実験的
実装 API
説明 Scribunto に任意精度演算を提供します。
作者
  • John Erling Blad (Jebladトーク)
最新バージョン 0.1.0
互換性の方針 master は後方互換性を維持しています。
MediaWiki >= 1.33
データベースの変更 いいえ
Composer jeblad/bcmath
ライセンス GNU 一般公衆利用許諾書 2.0 以降
ダウンロード
README, LDoc
  • $wgExtFiltering
BCmath 拡張機能の翻訳にご協力ください

BCmath は、Lua モジュール任意精度演算を提供します。 この拡張機能のlibを使用すると、125文字の𝜋 を計算しても全く問題ありません。𝜋 ≅ 3,141 592 653 589 793 238 462 643 383 279 502 884 197 169 399 375 105 820 974 944 592 307 816 406 286 208 998 628 034 825 342 117 067 982 148 086 513 282 306 647 093 8…(実際、本当の𝜋 はもっと 無限に長いです!)

この拡張機能はPHPのBCMath Arbitrary Precision Mathematicsapiを使用してphpseclib/bcmath_compatを使ってBC言語にアクセスするものです。

インストール

期待するのは、Scribunto 拡張機能に依存することです。

  • ダウンロードして、ファイルをextensions/フォルダー内のBCmathという名前のディレクトリ内に配置します。
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'BCmath' );
    
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

使用法

ワークフローとしては、まずBCmathのインスタンスを定義し、それを通常の方程式や連鎖的な演算、関数呼び出しの一部として使用します。 サポートされている操作にインスタンスが存在すると、特殊な関数やメソッドが使用されるようになります。

-- Used for chained operations
local sum1 = mw.bcmath.new( 0.0 ):add( 42.0 )                   -- 42.000000000000000
local sum2 = mw.bcmath.new( '0' ):add( '42' )                   -- 42

-- Used in an equation
local sum3 = sum1 * sum2 + 3.14                                 -- 1767.140000000000000

-- Used in function calls
local sum4 = mw.bcmath.add( mw.bcmath.mul( sum1, sum2 ), 3.14 ) -- 1767.140000000000000
local str1 = sum4 'sci'                                         -- 1.767140000000000000e3
local str2 = sum4( 'sci', 4 )                                   -- 1.767e3

さらに詳しいヘルプは、生成されたLDocのドキュメントを参照してください。

開発

Vagrantベースの開発環境の再構築については、BCmath: Manual/Vagrantを参照してください。

代替

The best and perhaps only real alternative is the decNumber C-library, which implements IEEE 754r, and the ldecNumber Lua wrapper library for interfacing with decNumber. この2つは必ず一緒に使ってください。

The decNumber library should have a security audit before it is used, but it is probably safe. The Lua library is archived, and is hopelessly outdated with a last version (ldecNumber-21) from August 2007. There are no known MediaWiki-integration for decNumber/ldecNumber.

関連項目