📄 calc.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../../displayToc.js"></script>
<script language="JavaScript" src="../../../tocParas.js"></script>
<script language="JavaScript" src="../../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../../scineplex.css">
<title>Math::BigInt::Calc - Pure Perl module to support Math::BigInt</title>
<link rel="stylesheet" href="../../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',3);</script>
<h1><a>Math::BigInt::Calc - Pure Perl module to support Math::BigInt</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#storage">STORAGE</a></li>
<li><a href="#methods">METHODS</a></li>
<li><a href="#wrap_your_own">WRAP YOUR OWN</a></li>
<li><a href="#license">LICENSE</a></li>
<li><a href="#authors">AUTHORS</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Math::BigInt::Calc - Pure Perl module to support Math::BigInt</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p>Provides support for big integer calculations. Not intended to be used by other
modules. Other modules which sport the same functions can also be used to support
Math::BigInt, like Math::BigInt::GMP or Math::BigInt::Pari.</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>In order to allow for multiple big integer libraries, Math::BigInt was
rewritten to use library modules for core math routines. Any module which
follows the same API as this can be used instead by using the following:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::BigInt</span> <span class="string">lib</span> <span class="operator">=></span> <span class="string">'libname'</span><span class="operator">;</span>
</pre>
<p>'libname' is either the long name ('Math::BigInt::Pari'), or only the short
version like 'Pari'.</p>
<p>
</p>
<hr />
<h1><a name="storage">STORAGE</a></h1>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<p>The following functions MUST be defined in order to support the use by
Math::BigInt v1.70 or later:</p>
<pre>
api_version() return API version, minimum 1 for v1.70
_new(string) return ref to new object from ref to decimal string
_zero() return a new object with value 0
_one() return a new object with value 1
_two() return a new object with value 2
_ten() return a new object with value 10</pre>
<pre>
_str(obj) return ref to a string representing the object
_num(obj) returns a Perl integer/floating point number
NOTE: because of Perl numeric notation defaults,
the _num'ified obj may lose accuracy due to
machine-dependend floating point size limitations
_add(obj,obj) Simple addition of two objects
_mul(obj,obj) Multiplication of two objects
_div(obj,obj) Division of the 1st object by the 2nd
In list context, returns (result,remainder).
NOTE: this is integer math, so no
fractional part will be returned.
The second operand will be not be 0, so no need to
check for that.
_sub(obj,obj) Simple subtraction of 1 object from another
a third, optional parameter indicates that the params
are swapped. In this case, the first param needs to
be preserved, while you can destroy the second.
sub (x,y,1) => return x - y and keep x intact!
_dec(obj) decrement object by one (input is garant. to be > 0)
_inc(obj) increment object by one</pre>
<pre>
_acmp(obj,obj) <=> operator for objects (return -1, 0 or 1)</pre>
<pre>
_len(obj) returns count of the decimal digits of the object
_digit(obj,n) returns the n'th decimal digit of object</pre>
<pre>
_is_one(obj) return true if argument is 1
_is_two(obj) return true if argument is 2
_is_ten(obj) return true if argument is 10
_is_zero(obj) return true if argument is 0
_is_even(obj) return true if argument is even (0,2,4,6..)
_is_odd(obj) return true if argument is odd (1,3,5,7..)</pre>
<pre>
_copy return a ref to a true copy of the object</pre>
<pre>
_check(obj) check whether internal representation is still intact
return 0 for ok, otherwise error message as string</pre>
<pre>
_from_hex(str) return ref to new object from ref to hexadecimal string
_from_bin(str) return ref to new object from ref to binary string
_as_hex(str) return string containing the value as
unsigned hex string, with the '0x' prepended.
Leading zeros must be stripped.
_as_bin(str) Like as_hex, only as binary string containing only
zeros and ones. Leading zeros must be stripped and a
'0b' must be prepended.
_rsft(obj,N,B) shift object in base B by N 'digits' right
_lsft(obj,N,B) shift object in base B by N 'digits' left
_xor(obj1,obj2) XOR (bit-wise) object 1 with object 2
Note: XOR, AND and OR pad with zeros if size mismatches
_and(obj1,obj2) AND (bit-wise) object 1 with object 2
_or(obj1,obj2) OR (bit-wise) object 1 with object 2</pre>
<pre>
_mod(obj,obj) Return remainder of div of the 1st by the 2nd object
_sqrt(obj) return the square root of object (truncated to int)
_root(obj) return the n'th (n >= 3) root of obj (truncated to int)
_fac(obj) return factorial of object 1 (1*2*3*4..)
_pow(obj,obj) return object 1 to the power of object 2
return undef for NaN
_zeros(obj) return number of trailing decimal zeros
_modinv return inverse modulus
_modpow return modulus of power ($x ** $y) % $z
_log_int(X,N) calculate integer log() of X in base N
X >= 0, N >= 0 (return undef for NaN)
returns (RESULT, EXACT) where EXACT is:
1 : result is exactly RESULT
0 : result was truncated to RESULT
undef : unknown whether result is exactly RESULT
_gcd(obj,obj) return Greatest Common Divisor of two objects</pre>
<p>The following functions are optional, and can be defined if the underlying lib
has a fast way to do them. If undefined, Math::BigInt will use pure Perl (hence
slow) fallback routines to emulate these:</p>
<pre>
_signed_or
_signed_and
_signed_xor</pre>
<p>Input strings come in as unsigned but with prefix (i.e. as '123', '0xabc'
or '0b1101').</p>
<p>So the library needs only to deal with unsigned big integers. Testing of input
parameter validity is done by the caller, so you need not worry about
underflow (f.i. in <code>_sub()</code>, <code>_dec()</code>) nor about division by zero or similar
cases.</p>
<p>The first parameter can be modified, that includes the possibility that you
return a reference to a completely different object instead. Although keeping
the reference and just changing it's contents is prefered over creating and
returning a different reference.</p>
<p>Return values are always references to objects, strings, or true/false for
comparisation routines.</p>
<p>
</p>
<hr />
<h1><a name="wrap_your_own">WRAP YOUR OWN</a></h1>
<p>If you want to port your own favourite c-lib for big numbers to the
Math::BigInt interface, you can take any of the already existing modules as
a rough guideline. You should really wrap up the latest BigInt and BigFloat
testsuites with your module, and replace in them any of the following:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::BigInt</span><span class="operator">;</span>
</pre>
<p>by this:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Math::BigInt</span> <span class="string">lib</span> <span class="operator">=></span> <span class="string">'yourlib'</span><span class="operator">;</span>
</pre>
<p>This way you ensure that your library really works 100% within Math::BigInt.</p>
<p>
</p>
<hr />
<h1><a name="license_this_program_is_free_software__you_may_redistribute_it_and_or_modify_it_under_the_same_terms_as_perl_itself_">LICENSE
This program is free software; you may redistribute it and/or modify it under
the same terms as Perl itself.</a></h1>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Original math code by Mark Biggar, rewritten by Tels <a href="http://bloodgate.com/">http://bloodgate.com/</a>
in late 2000.
Seperated from BigInt and shaped API with the help of John Peacock.</p>
<p>Fixed, speed-up, streamlined and enhanced by Tels 2001 - 2005.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../../lib/Math/BigInt.html">the Math::BigInt manpage</a>, <a href="../../../lib/Math/BigFloat.html">the Math::BigFloat manpage</a>, <a href="../../../Math/BigInt/BitVect.html">the Math::BigInt::BitVect manpage</a>,
<a href="../../../Math/BigInt/GMP.html">the Math::BigInt::GMP manpage</a>, <a href="../../../lib/Math/BigInt/FastCalc.html">the Math::BigInt::FastCalc manpage</a> and <a href="../../../Math/BigInt/Pari.html">the Math::BigInt::Pari manpage</a>.</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -