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>bigrat - Transparent BigNumber/BigRational 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"> bigrat - Transparent BigNumber/BigRational 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=
"#modules_used">Modules Used
</a></li>
28 <li><a href=
"#math_library">Math Library
</a></li>
29 <li><a href=
"#sign">Sign
</a></li>
30 <li><a href=
"#methods">Methods
</a></li>
31 <li><a href=
"#cavaet">Cavaet
</a></li>
32 <li><a href=
"#options">Options
</a></li>
35 <li><a href=
"#examples">EXAMPLES
</a></li>
36 <li><a href=
"#license">LICENSE
</a></li>
37 <li><a href=
"#see_also">SEE ALSO
</a></li>
38 <li><a href=
"#authors">AUTHORS
</a></li>
45 <h1><a name=
"name">NAME
</a></h1>
46 <p>bigrat - Transparent BigNumber/BigRational support for Perl
</p>
50 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
54 $x =
2 +
4.5,
"\n
"; # BigFloat
6.5
55 print
1/
3 +
1/
4,
"\n
"; # produces
7/
12</pre>
59 <h1><a name=
"description">DESCRIPTION
</a></h1>
60 <p>All operators (inlcuding basic math operations) are overloaded. Integer and
61 floating-point constants are created as proper BigInts or BigFloats,
63 <p>Other than
<a href=
"file://C|\msysgit\mingw\html/lib/bignum.html">the bignum manpage
</a>, this module upgrades to Math::BigRat, meaning that
64 instead of
2.5 you will get
2+
1/
2 as output.
</p>
67 <h2><a name=
"modules_used">Modules Used
</a></h2>
68 <p><code>bigrat
</code> is just a thin wrapper around various modules of the Math::BigInt
69 family. Think of it as the head of the family, who runs the shop, and orders
70 the others to do the work.
</p>
71 <p>The following modules are currently used by bignum:
</p>
73 Math::BigInt::Lite (for speed, and only if it is loadable)
79 <h2><a name=
"math_library">Math Library
</a></h2>
80 <p>Math with the numbers is done (by default) by a module called
81 Math::BigInt::Calc. This is equivalent to saying:
</p>
83 use bigrat lib =
> 'Calc';
</pre>
84 <p>You can change this by using:
</p>
86 use bigrat lib =
> 'BitVect';
</pre>
87 <p>The following would first try to find Math::BigInt::Foo, then
88 Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:
</p>
90 use bigrat lib =
> 'Foo,Math::BigInt::Bar';
</pre>
91 <p>Please see respective module documentation for further details.
</p>
94 <h2><a name=
"sign">Sign
</a></h2>
95 <p>The sign is either '+', '-', 'NaN', '+inf' or '-inf'.
</p>
96 <p>A sign of 'NaN' is used to represent the result when input arguments are not
97 numbers or as a result of
0/
0. '+inf' and '-inf' represent plus respectively
98 minus infinity. You will get '+inf' when dividing a positive number by
0, and
99 '-inf' when dividing any negative number by
0.
</p>
102 <h2><a name=
"methods">Methods
</a></h2>
103 <p>Since all numbers are not objects, you can use all functions that are part of
104 the BigInt or BigFloat API. It is wise to use only the
<code>bxxx()
</code> notation, and not
105 the
<code>fxxx()
</code> notation, though. This makes you independed on the fact that the
106 underlying object might morph into a different class than BigFloat.
</p>
109 <h2><a name=
"cavaet">Cavaet
</a></h2>
110 <p>But a warning is in order. When using the following to make a copy of a number,
111 only a shallow copy will be made.
</p>
115 <p>If you want to make a real copy, use the following:
</p>
117 $y = $x-
>copy();
</pre>
118 <p>Using the copy or the original with overloaded math is okay, e.g. the
122 print $x +
1,
" ", $y,
"\n
"; # prints
10 9</pre>
123 <p>but calling any method that modifies the number directly will result in
124 <strong>both
</strong> the original and the copy beeing destroyed:
</p>
127 print $x-
>badd(
1),
" ", $y,
"\n
"; # prints
10 10</pre>
130 print $x-
>binc(
1),
" ", $y,
"\n
"; # prints
10 10</pre>
133 print $x-
>bmul(
2),
" ", $y,
"\n
"; # prints
18 18</pre>
134 <p>Using methods that do not modify, but testthe contents works:
</p>
137 $z =
9 if $x-
>is_zero(); # works fine
</pre>
138 <p>See the documentation about the copy constructor and
<code>=
</code> in overload, as
139 well as the documentation in BigInt for further details.
</p>
142 <h2><a name=
"options">Options
</a></h2>
143 <p>bignum recognizes some options that can be passed while loading it via use.
144 The options can (currently) be either a single letter form, or the long form.
145 The following options exist:
</p>
147 <dt><strong><a name=
"item_a_or_accuracy">a or accuracy
</a></strong>
150 <p>This sets the accuracy for all math operations. The argument must be greater
151 than or equal to zero. See Math::BigInt's
<code>bround()
</code> function for details.
</p>
155 perl -Mbigrat=a,
50 -le 'print sqrt(
20)'
</pre>
158 <dt><strong><a name=
"item_p_or_precision">p or precision
</a></strong>
161 <p>This sets the precision for all math operations. The argument can be any
162 integer. Negative values mean a fixed number of digits after the dot, while
163 a positive value rounds to this digit left from the dot.
0 or
1 mean round to
164 integer. See Math::BigInt's
<code>bfround()
</code> function for details.
</p>
168 perl -Mbigrat=p,-
50 -le 'print sqrt(
20)'
</pre>
171 <dt><strong><a name=
"item_t_or_trace">t or trace
</a></strong>
174 <p>This enables a trace mode and is primarily for debugging bignum or
175 Math::BigInt/Math::BigFloat.
</p>
178 <dt><strong><a name=
"item_l_or_lib">l or lib
</a></strong>
181 <p>Load a different math lib, see
<a href=
"#math_library">MATH LIBRARY
</a>.
</p>
185 perl -Mbigrat=l,GMP -e 'print
2 **
512'
</pre>
188 <p>Currently there is no way to specify more than one library on the command
189 line. This will be hopefully fixed soon ;)
</p>
192 <dt><strong><a name=
"item_v_or_version">v or version
</a></strong>
195 <p>This prints out the name and version of all modules used and then exits.
</p>
199 perl -Mbigrat=v
</pre>
206 <h1><a name=
"examples">EXAMPLES
</a></h1>
209 perl -Mbigrat -le 'print sqrt(
33)'
210 perl -Mbigrat -le 'print
2*
255'
211 perl -Mbigrat -le 'print
4.5+
2*
255'
212 perl -Mbigrat -le 'print
3/
7 +
5/
7 +
8/
3'
213 perl -Mbigrat -le 'print
12-
>is_odd()';
</pre>
217 <h1><a name=
"license">LICENSE
</a></h1>
218 <p>This program is free software; you may redistribute it and/or modify it under
219 the same terms as Perl itself.
</p>
223 <h1><a name=
"see_also">SEE ALSO
</a></h1>
224 <p>Especially
<a href=
"file://C|\msysgit\mingw\html/lib/bignum.html">the bignum manpage
</a>.
</p>
225 <p><a href=
"file://C|\msysgit\mingw\html/lib/Math/BigFloat.html">the Math::BigFloat manpage
</a>,
<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
226 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>.
</p>
230 <h1><a name=
"authors">AUTHORS
</a></h1>
231 <p>(C) by Tels
<a href=
"http://bloodgate.com/">http://bloodgate.com/
</a> in early
2002 -
2005.
</p>
232 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
233 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
234 <big><strong><span class=
"block"> bigrat - Transparent BigNumber/BigRational support for Perl
</span></strong></big>