2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>bigint - Transparent BigInteger support for Perl
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> bigint - Transparent BigInteger support for Perl
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
27 <li><a href=
"#options">Options
</a></li>
28 <li><a href=
"#math_library">Math Library
</a></li>
29 <li><a href=
"#internal_format">Internal Format
</a></li>
30 <li><a href=
"#sign">Sign
</a></li>
31 <li><a href=
"#methods">Methods
</a></li>
32 <li><a href=
"#caveat">Caveat
</a></li>
35 <li><a href=
"#modules_used">MODULES USED
</a></li>
36 <li><a href=
"#examples">EXAMPLES
</a></li>
37 <li><a href=
"#license">LICENSE
</a></li>
38 <li><a href=
"#see_also">SEE ALSO
</a></li>
39 <li><a href=
"#authors">AUTHORS
</a></li>
46 <h1><a name=
"name">NAME
</a></h1>
47 <p>bigint - Transparent BigInteger support for Perl
</p>
51 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
55 $x =
2 +
4.5,
"\n
"; # BigInt
6
56 print
2 **
512,
"\n
"; # really is what you think it is
57 print inf +
42,
"\n
"; # inf
58 print NaN *
7,
"\n
"; # NaN
</pre>
62 <h1><a name=
"description">DESCRIPTION
</a></h1>
63 <p>All operators (including basic math operations) are overloaded. Integer
64 constants are created as proper BigInts.
</p>
65 <p>Floating point constants are truncated to integer. All results are also
69 <h2><a name=
"options">Options
</a></h2>
70 <p>bigint recognizes some options that can be passed while loading it via use.
71 The options can (currently) be either a single letter form, or the long form.
72 The following options exist:
</p>
74 <dt><strong><a name=
"item_a_or_accuracy">a or accuracy
</a></strong>
77 <p>This sets the accuracy for all math operations. The argument must be greater
78 than or equal to zero. See Math::BigInt's
<code>bround()
</code> function for details.
</p>
82 perl -Mbigint=a,
2 -le 'print
12345+
1'
</pre>
85 <dt><strong><a name=
"item_p_or_precision">p or precision
</a></strong>
88 <p>This sets the precision for all math operations. The argument can be any
89 integer. Negative values mean a fixed number of digits after the dot, and
90 are
<B
>ignored
</B
> since all operations happen in integer space.
91 A positive value rounds to this digit left from the dot.
0 or
1 mean round to
92 integer and are ignore like negative values.
</p>
95 <p>See Math::BigInt's
<code>bfround()
</code> function for details.
</p>
99 perl -Mbignum=p,
5 -le 'print
123456789+
123'
</pre>
102 <dt><strong><a name=
"item_t_or_trace">t or trace
</a></strong>
105 <p>This enables a trace mode and is primarily for debugging bigint or
109 <dt><strong><a name=
"item_l_or_lib">l or lib
</a></strong>
112 <p>Load a different math lib, see
<a href=
"#math_library">MATH LIBRARY
</a>.
</p>
116 perl -Mbigint=l,GMP -e 'print
2 **
512'
</pre>
119 <p>Currently there is no way to specify more than one library on the command
120 line. This will be hopefully fixed soon ;)
</p>
123 <dt><strong><a name=
"item_v_or_version">v or version
</a></strong>
126 <p>This prints out the name and version of all modules used and then exits.
</p>
130 perl -Mbigint=v
</pre>
136 <h2><a name=
"math_library">Math Library
</a></h2>
137 <p>Math with the numbers is done (by default) by a module called
138 Math::BigInt::Calc. This is equivalent to saying:
</p>
140 use bigint lib =
> 'Calc';
</pre>
141 <p>You can change this by using:
</p>
143 use bigint lib =
> 'BitVect';
</pre>
144 <p>The following would first try to find Math::BigInt::Foo, then
145 Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:
</p>
147 use bigint lib =
> 'Foo,Math::BigInt::Bar';
</pre>
148 <p>Please see respective module documentation for further details.
</p>
151 <h2><a name=
"internal_format">Internal Format
</a></h2>
152 <p>The numbers are stored as objects, and their internals might change at anytime,
153 especially between math operations. The objects also might belong to different
154 classes, like Math::BigInt, or Math::BigInt::Lite. Mixing them together, even
155 with normal scalars is not extraordinary, but normal and expected.
</p>
156 <p>You should not depend on the internal format, all accesses must go through
157 accessor methods. E.g. looking at $x-
>{sign} is not a good idea since there
158 is no guaranty that the object in question has such a hash key, nor is a hash
159 underneath at all.
</p>
162 <h2><a name=
"sign">Sign
</a></h2>
163 <p>The sign is either '+', '-', 'NaN', '+inf' or '-inf'.
164 You can access it with the
<code>sign()
</code> method.
</p>
165 <p>A sign of 'NaN' is used to represent the result when input arguments are not
166 numbers or as a result of
0/
0. '+inf' and '-inf' represent plus respectively
167 minus infinity. You will get '+inf' when dividing a positive number by
0, and
168 '-inf' when dividing any negative number by
0.
</p>
171 <h2><a name=
"methods">Methods
</a></h2>
172 <p>Since all numbers are now objects, you can use all functions that are part of
173 the BigInt API. You can only use the
<code>bxxx()
</code> notation, and not the
<code>fxxx()
</code>
174 notation, though.
</p>
177 <h2><a name=
"caveat">Caveat
</a></h2>
178 <p>But a warning is in order. When using the following to make a copy of a number,
179 only a shallow copy will be made.
</p>
183 <p>Using the copy or the original with overloaded math is okay, e.g. the
187 print $x +
1,
" ", $y,
"\n
"; # prints
10 9</pre>
188 <p>but calling any method that modifies the number directly will result in
189 <strong>both
</strong> the original and the copy beeing destroyed:
194 print $x-
>badd(
1),
" ", $y,
"\n
"; # prints
10 10</pre>
198 print $x-
>binc(
1),
" ", $y,
"\n
"; # prints
10 10</pre>
202 print $x-
>bmul(
2),
" ", $y,
"\n
"; # prints
18 18</pre>
205 Using methods that do not modify, but testthe contents works:
</pre>
208 $z =
9 if $x-
>is_zero(); # works fine
</pre>
209 <p>See the documentation about the copy constructor and
<code>=
</code> in overload, as
210 well as the documentation in BigInt for further details.
</p>
214 <h1><a name=
"modules_used">MODULES USED
</a></h1>
215 <p><code>bigint
</code> is just a thin wrapper around various modules of the Math::BigInt
216 family. Think of it as the head of the family, who runs the shop, and orders
217 the others to do the work.
</p>
218 <p>The following modules are currently used by bigint:
</p>
220 Math::BigInt::Lite (for speed, and only if it is loadable)
225 <h1><a name=
"examples">EXAMPLES
</a></h1>
226 <p>Some cool command line examples to impress the Python crowd ;) You might want
227 to compare them to the results under -Mbignum or -Mbigrat:
231 perl -Mbigint -le 'print sqrt(
33)'
232 perl -Mbigint -le 'print
2*
255'
233 perl -Mbigint -le 'print
4.5+
2*
255'
234 perl -Mbigint -le 'print
3/
7 +
5/
7 +
8/
3'
235 perl -Mbigint -le 'print
123-
>is_odd()'
236 perl -Mbigint -le 'print log(
2)'
237 perl -Mbigint -le 'print
2 **
0.5'
238 perl -Mbigint=a,
65 -le 'print
2 **
0.2'
</pre>
242 <h1><a name=
"license">LICENSE
</a></h1>
243 <p>This program is free software; you may redistribute it and/or modify it under
244 the same terms as Perl itself.
</p>
248 <h1><a name=
"see_also">SEE ALSO
</a></h1>
249 <p>Especially
<a href=
"file://C|\msysgit\mingw\html/lib/bigrat.html">the bigrat manpage
</a> as in
<code>perl -Mbigrat -le 'print
1/
3+
1/
4'
</code> and
250 <a href=
"file://C|\msysgit\mingw\html/lib/bignum.html">the bignum manpage
</a> as in
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_sqrt"><code>perl -Mbignum -le 'print sqrt(
2)'
</code></a>.
253 <p><a href=
"file://C|\msysgit\mingw\html/lib/Math/BigInt.html">the Math::BigInt manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/lib/Math/BigRat.html">the Math::BigRat manpage
</a> and
<a href=
"file://C|\msysgit\mingw\html/Math/Big.html">the Math::Big manpage
</a> as well
254 as
<a href=
"file://C|\msysgit\mingw\html/Math/BigInt/BitVect.html">the Math::BigInt::BitVect manpage
</a>,
<a href=
"file://C|\msysgit\mingw\html/Math/BigInt/Pari.html">the Math::BigInt::Pari manpage
</a> and
<a href=
"file://C|\msysgit\mingw\html/Math/BigInt/GMP.html">the Math::BigInt::GMP manpage
</a>.
260 <h1><a name=
"authors">AUTHORS
</a></h1>
261 <p>(C) by Tels
<a href=
"http://bloodgate.com/">http://bloodgate.com/
</a> in early
2002 -
2005.
264 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
265 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
266 <big><strong><span class=
"block"> bigint - Transparent BigInteger support for Perl
</span></strong></big>