Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / bigrat.html
blobf4da4465f28aac32c36fd0609fb89fb34385393a
1 <?xml version="1.0" ?>
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">
4 <head>
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:" />
8 </head>
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">&nbsp;bigrat - Transparent BigNumber/BigRational support for Perl</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <ul>
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>
33 </ul>
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>
39 </ul>
40 <!-- INDEX END -->
42 <hr />
43 <p>
44 </p>
45 <h1><a name="name">NAME</a></h1>
46 <p>bigrat - Transparent BigNumber/BigRational support for Perl</p>
47 <p>
48 </p>
49 <hr />
50 <h1><a name="synopsis">SYNOPSIS</a></h1>
51 <pre>
52 use bigrat;</pre>
53 <pre>
54 $x = 2 + 4.5,&quot;\n&quot;; # BigFloat 6.5
55 print 1/3 + 1/4,&quot;\n&quot;; # produces 7/12</pre>
56 <p>
57 </p>
58 <hr />
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,
62 respectively.</p>
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>
65 <p>
66 </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>
72 <pre>
73 Math::BigInt::Lite (for speed, and only if it is loadable)
74 Math::BigInt
75 Math::BigFloat
76 Math::BigRat</pre>
77 <p>
78 </p>
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>
82 <pre>
83 use bigrat lib =&gt; 'Calc';</pre>
84 <p>You can change this by using:</p>
85 <pre>
86 use bigrat lib =&gt; '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>
89 <pre>
90 use bigrat lib =&gt; 'Foo,Math::BigInt::Bar';</pre>
91 <p>Please see respective module documentation for further details.</p>
92 <p>
93 </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>
101 </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>
108 </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>
112 <pre>
113 $x = 9; $y = $x;
114 $x = $y = 7;</pre>
115 <p>If you want to make a real copy, use the following:</p>
116 <pre>
117 $y = $x-&gt;copy();</pre>
118 <p>Using the copy or the original with overloaded math is okay, e.g. the
119 following work:</p>
120 <pre>
121 $x = 9; $y = $x;
122 print $x + 1, &quot; &quot;, $y,&quot;\n&quot;; # 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>
125 <pre>
126 $x = 9; $y = $x;
127 print $x-&gt;badd(1), &quot; &quot;, $y,&quot;\n&quot;; # prints 10 10</pre>
128 <pre>
129 $x = 9; $y = $x;
130 print $x-&gt;binc(1), &quot; &quot;, $y,&quot;\n&quot;; # prints 10 10</pre>
131 <pre>
132 $x = 9; $y = $x;
133 print $x-&gt;bmul(2), &quot; &quot;, $y,&quot;\n&quot;; # prints 18 18</pre>
134 <p>Using methods that do not modify, but testthe contents works:</p>
135 <pre>
136 $x = 9; $y = $x;
137 $z = 9 if $x-&gt;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>
141 </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>
146 <dl>
147 <dt><strong><a name="item_a_or_accuracy">a or accuracy</a></strong>
149 <dd>
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>
152 </dd>
153 <dd>
154 <pre>
155 perl -Mbigrat=a,50 -le 'print sqrt(20)'</pre>
156 </dd>
157 </li>
158 <dt><strong><a name="item_p_or_precision">p or precision</a></strong>
160 <dd>
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>
165 </dd>
166 <dd>
167 <pre>
168 perl -Mbigrat=p,-50 -le 'print sqrt(20)'</pre>
169 </dd>
170 </li>
171 <dt><strong><a name="item_t_or_trace">t or trace</a></strong>
173 <dd>
174 <p>This enables a trace mode and is primarily for debugging bignum or
175 Math::BigInt/Math::BigFloat.</p>
176 </dd>
177 </li>
178 <dt><strong><a name="item_l_or_lib">l or lib</a></strong>
180 <dd>
181 <p>Load a different math lib, see <a href="#math_library">MATH LIBRARY</a>.</p>
182 </dd>
183 <dd>
184 <pre>
185 perl -Mbigrat=l,GMP -e 'print 2 ** 512'</pre>
186 </dd>
187 <dd>
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>
190 </dd>
191 </li>
192 <dt><strong><a name="item_v_or_version">v or version</a></strong>
194 <dd>
195 <p>This prints out the name and version of all modules used and then exits.</p>
196 </dd>
197 <dd>
198 <pre>
199 perl -Mbigrat=v</pre>
200 </dd>
201 </li>
202 </dl>
204 </p>
205 <hr />
206 <h1><a name="examples">EXAMPLES</a></h1>
207 <pre>
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-&gt;is_odd()';</pre>
215 </p>
216 <hr />
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>
221 </p>
222 <hr />
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>
228 </p>
229 <hr />
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">&nbsp;bigrat - Transparent BigNumber/BigRational support for Perl</span></strong></big>
235 </td></tr>
236 </table>
238 </body>
240 </html>