=encoding euc-jp
=head1 NAME
=begin original
bignum - Transparent BigNumber support for Perl
=end original
bignum - Perl 用の透過的な BigNumber 対応
=head1 SYNOPSIS
use bignum;
$x = 2 + 4.5,"\n"; # BigFloat 6.5
print 2 ** 512 * 0.1,"\n"; # really is what you think it is
print inf * inf,"\n"; # prints inf
print NaN * 3,"\n"; # prints NaN
{
no bignum;
print 2 ** 256,"\n"; # a normal Perl scalar now
}
# for older Perls, note that this will be global:
use bignum qw/hex oct/;
print hex("0x1234567890123490"),"\n";
print oct("01234567890123490"),"\n";
=head1 DESCRIPTION
=begin original
All operators (including basic math operations) are overloaded. Integer and
floating-point constants are created as proper BigInts or BigFloats,
respectively.
=end original
(基本算術演算子を含む)全ての演算子がオーバーロードされます。
整数定数と浮動小数点数定数はそれぞれ適切な BigInt または BigFloat として
作成されます。
=begin original
If you do
=end original
このように
use bignum;
=begin original
at the top of your script, Math::BigFloat and Math::BigInt will be loaded
and any constant number will be converted to an object (Math::BigFloat for
floats like 3.1415 and Math::BigInt for integers like 1234).
=end original
スクリプトの先頭に書くと、Math::BigFloat と Math::BigInt が読み込まれ、
全ての定数はオブジェクトに変換されます (3.1415 のようは浮動小数点数は
Math::BigFloat に、1234 のような整数は Math::BigInt に)。
=begin original
So, the following line:
=end original
それで、以下の行は:
$x = 1234;
=begin original
creates actually a Math::BigInt and stores a reference to in $x.
This happens transparently and behind your back, so to speak.
=end original
実際には Math::BigInt を作成して、リファレンスを $x に保管します。
これは透過的に、いわば背後で行われます。
=begin original
You can see this with the following:
=end original
以下のようにすればこれを見ることができます:
perl -Mbignum -le 'print ref(1234)'
=begin original
Don't worry if it says Math::BigInt::Lite, bignum and friends will use Lite
if it is installed since it is faster for some operations. It will be
automatically upgraded to BigInt whenever necessary:
=end original
Math::BigInt::Lite と言われても気にしないで下さい; bignum および
親類は、Lite がインストールされている場合は使います; これはいくつかの
演算がより速いからです。
もし必要なら自動的に BigInt に昇格します:
perl -Mbignum -le 'print ref(2**255)'
=begin original
This also means it is a bad idea to check for some specific package, since
the actual contents of $x might be something unexpected. Due to the
transparent way of bignum C[ should not be necessary, anyway.
=end original
これは、$x の実際の内容は不確定なので、特定のパッケージかどうかを
チェックするというのは良くない考えであることも示しています。
とにかく、bignum での C][ の透過的な方法は不要のはずです。
=begin original
Since Math::BigInt and BigFloat also overload the normal math operations,
the following line will still work:
=end original
Math::BigInt と BigFloat は通常の算術演算もオーバーロードするので、
以下のような行も動作するままです:
perl -Mbignum -le 'print ref(1234+1234)'
=begin original
Since numbers are actually objects, you can call all the usual methods from
BigInt/BigFloat on them. This even works to some extent on expressions:
=end original
数値は実際にはオブジェクトなので、使われている BigInt/BigFloat の全ての
通常のメソッドを呼び出すことができます。
これは式のいくつかの拡張に対してさえ動作します:
perl -Mbignum -le '$x = 1234; print $x->bdec()'
perl -Mbignum -le 'print 1234->copy()->binc();'
perl -Mbignum -le 'print 1234->copy()->binc->badd(6);'
perl -Mbignum -le 'print +(1234)->copy()->binc()'
=begin original
(Note that print doesn't do what you expect if the expression starts with
'(' hence the C<+>)
=end original
(Note that print doesn't do what you expect if the expression starts with
'(' hence the C<+>)
(TBT)
=begin original
You can even chain the operations together as usual:
=end original
You can even chain the operations together as usual:
(TBT)
perl -Mbignum -le 'print 1234->copy()->binc->badd(6);'
1241
=begin original
Under bignum (or bigint or bigrat), Perl will "upgrade" the numbers
appropriately. This means that:
=end original
Under bignum (or bigint or bigrat), Perl will "upgrade" the numbers
appropriately. This means that:
(TBT)
perl -Mbignum -le 'print 1234+4.5'
1238.5
=begin original
will work correctly. These mixed cases don't do always work when using
Math::BigInt or Math::BigFloat alone, or at least not in the way normal Perl
scalars work.
=end original
will work correctly. These mixed cases don't do always work when using
Math::BigInt or Math::BigFloat alone, or at least not in the way normal Perl
scalars work.
(TBT)
=begin original
If you do want to work with large integers like under C]