.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::BigInt::Calc 3perl" .TH Math::BigInt::Calc 3perl "2014-12-27" "perl v5.20.2" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Math::BigInt::Calc \- Pure Perl module to support Math::BigInt .SH "SYNOPSIS" .IX Header "SYNOPSIS" This library provides support for big integer calculations. It is not intended to be used by other modules. Other modules which support the same \&\s-1API \s0(see below) can also be used to support Math::BigInt, like Math::BigInt::GMP and Math::BigInt::Pari. .SH "DESCRIPTION" .IX Header "DESCRIPTION" In this library, the numbers are represented in base B = 10**N, where N is the largest possible value that does not cause overflow in the intermediate computations. The base B elements are stored in an array, with the least significant element stored in array element zero. There are no leading zero elements, except a single zero element when the number is zero. .PP For instance, if B = 10000, the number 1234567890 is represented internally as [3456, 7890, 12]. .SH "THE Math::BigInt API" .IX Header "THE Math::BigInt API" In order to allow for multiple big integer libraries, Math::BigInt was rewritten to use a plug-in library for core math routines. Any module which conforms to the \s-1API\s0 can be used by Math::BigInt by using this in your program: .PP .Vb 1 \& use Math::BigInt lib => \*(Aqlibname\*(Aq; .Ve .PP \&'libname' is either the long name, like 'Math::BigInt::Pari', or only the short version, like 'Pari'. .SS "General Notes" .IX Subsection "General Notes" A library only needs to deal with unsigned big integers. Testing of input parameter validity is done by the caller, so there is no need to worry about underflow (e.g., in \f(CW\*(C`_sub()\*(C'\fR and \f(CW\*(C`_dec()\*(C'\fR) nor about division by zero (e.g., in \f(CW\*(C`_div()\*(C'\fR) or similar cases. .PP For some methods, 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 its contents is preferred over creating and returning a different reference. .PP Return values are always objects, strings, Perl scalars, or true/false for comparison routines. .SS "\s-1API\s0 version 1" .IX Subsection "API version 1" The following methods must be defined in order to support the use by Math::BigInt v1.70 or later. .PP \fI\s-1API\s0 version\fR .IX Subsection "API version" .IP "\fI\fIapi_version()\fI\fR" 4 .IX Item "api_version()" Return \s-1API\s0 version as a Perl scalar, 1 for Math::BigInt v1.70, 2 for Math::BigInt v1.83. .PP \fIConstructors\fR .IX Subsection "Constructors" .IP "\fI_new(\s-1STR\s0)\fR" 4 .IX Item "_new(STR)" Convert a string representing an unsigned decimal number to an object representing the same number. The input is normalize, i.e., it matches \&\f(CW\*(C`^(0|[1\-9]\ed*)$\*(C'\fR. .IP "\fI\fI_zero()\fI\fR" 4 .IX Item "_zero()" Return an object representing the number zero. .IP "\fI\fI_one()\fI\fR" 4 .IX Item "_one()" Return an object representing the number one. .IP "\fI\fI_two()\fI\fR" 4 .IX Item "_two()" Return an object representing the number two. .IP "\fI\fI_ten()\fI\fR" 4 .IX Item "_ten()" Return an object representing the number ten. .IP "\fI_from_bin(\s-1STR\s0)\fR" 4 .IX Item "_from_bin(STR)" Return an object given a string representing a binary number. The input has a \&'0b' prefix and matches the regular expression \f(CW\*(C`^0[bB](0|1[01]*)$\*(C'\fR. .IP "\fI_from_oct(\s-1STR\s0)\fR" 4 .IX Item "_from_oct(STR)" Return an object given a string representing an octal number. The input has a \&'0' prefix and matches the regular expression \f(CW\*(C`^0[1\-7]*$\*(C'\fR. .IP "\fI_from_hex(\s-1STR\s0)\fR" 4 .IX Item "_from_hex(STR)" Return an object given a string representing a hexadecimal number. The input has a '0x' prefix and matches the regular expression \&\f(CW\*(C`^0x(0|[1\-9a\-fA\-F][\eda\-fA\-F]*)$\*(C'\fR. .PP \fIMathematical functions\fR .IX Subsection "Mathematical functions" .PP Each of these methods may modify the first input argument, except \fI\fI_bgcd()\fI\fR, which shall not modify any input argument, and \fI\fI_sub()\fI\fR which may modify the second input argument. .IP "\fI_add(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_add(OBJ1, OBJ2)" Returns the result of adding \s-1OBJ2\s0 to \s-1OBJ1.\s0 .IP "\fI_mul(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_mul(OBJ1, OBJ2)" Returns the result of multiplying \s-1OBJ2\s0 and \s-1OBJ1.\s0 .IP "\fI_div(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_div(OBJ1, OBJ2)" Returns the result of dividing \s-1OBJ1\s0 by \s-1OBJ2\s0 and truncating the result to an integer. .IP "\fI_sub(\s-1OBJ1, OBJ2, FLAG\s0)\fR" 4 .IX Item "_sub(OBJ1, OBJ2, FLAG)" .PD 0 .IP "\fI_sub(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_sub(OBJ1, OBJ2)" .PD Returns the result of subtracting \s-1OBJ2\s0 by \s-1OBJ1.\s0 If \f(CW\*(C`flag\*(C'\fR is false or omitted, \&\s-1OBJ1\s0 might be modified. If \f(CW\*(C`flag\*(C'\fR is true, \s-1OBJ2\s0 might be modified. .IP "\fI_dec(\s-1OBJ\s0)\fR" 4 .IX Item "_dec(OBJ)" Decrement \s-1OBJ\s0 by one. .IP "\fI_inc(\s-1OBJ\s0)\fR" 4 .IX Item "_inc(OBJ)" Increment \s-1OBJ\s0 by one. .IP "\fI_mod(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_mod(OBJ1, OBJ2)" Return \s-1OBJ1\s0 modulo \s-1OBJ2,\s0 i.e., the remainder after dividing \s-1OBJ1\s0 by \s-1OBJ2.\s0 .IP "\fI_sqrt(\s-1OBJ\s0)\fR" 4 .IX Item "_sqrt(OBJ)" Return the square root of the object, truncated to integer. .IP "\fI_root(\s-1OBJ, N\s0)\fR" 4 .IX Item "_root(OBJ, N)" Return Nth root of the object, truncated to int. N is >= 3. .IP "\fI_fac(\s-1OBJ\s0)\fR" 4 .IX Item "_fac(OBJ)" Return factorial of object (1*2*3*4*...). .IP "\fI_pow(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_pow(OBJ1, OBJ2)" Return \s-1OBJ1\s0 to the power of \s-1OBJ2.\s0 By convention, 0**0 = 1. .IP "\fI_modinv(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_modinv(OBJ1, OBJ2)" Return modular multiplicative inverse, i.e., return \s-1OBJ3\s0 so that .Sp .Vb 1 \& (OBJ3 * OBJ1) % OBJ2 = 1 % OBJ2 .Ve .Sp The result is returned as two arguments. If the modular multiplicative inverse does not exist, both arguments are undefined. Otherwise, the arguments are a number (object) and its sign (\*(L"+\*(R" or \*(L"\-\*(R"). .Sp The output value, with its sign, must either be a positive value in the range 1,2,...,OBJ2\-1 or the same value subtracted \s-1OBJ2.\s0 For instance, if the input arguments are objects representing the numbers 7 and 5, the method must either return an object representing the number 3 and a \*(L"+\*(R" sign, since (3*7) % 5 = 1 % 5, or an object representing the number 2 and \*(L"\-\*(R" sign, since (\-2*7) % 5 = 1 % 5. .IP "\fI_modpow(\s-1OBJ1, OBJ2, OBJ3\s0)\fR" 4 .IX Item "_modpow(OBJ1, OBJ2, OBJ3)" Return modular exponentiation, (\s-1OBJ1\s0 ** \s-1OBJ2\s0) % \s-1OBJ3.\s0 .IP "\fI_rsft(\s-1OBJ, N, B\s0)\fR" 4 .IX Item "_rsft(OBJ, N, B)" Shift object N digits right in base B and return the resulting object. This is equivalent to performing integer division by B**N and discarding the remainder, except that it might be much faster, depending on how the number is represented internally. .Sp For instance, if the object \f(CW$obj\fR represents the hexadecimal number 0xabcde, then \f(CW\*(C`_rsft($obj, 2, 16)\*(C'\fR returns an object representing the number 0xabc. The \&\*(L"remainer\*(R", 0xde, is discarded and not returned. .IP "\fI_lsft(\s-1OBJ, N, B\s0)\fR" 4 .IX Item "_lsft(OBJ, N, B)" Shift the object N digits left in base B. This is equivalent to multiplying by B**N, except that it might be much faster, depending on how the number is represented internally. .IP "\fI_log_int(\s-1OBJ, B\s0)\fR" 4 .IX Item "_log_int(OBJ, B)" Return integer log of \s-1OBJ\s0 to base \s-1BASE.\s0 This method has two output arguments, the \s-1OBJECT\s0 and a \s-1STATUS.\s0 The \s-1STATUS\s0 is Perl scalar; it is 1 if \s-1OBJ\s0 is the exact result, 0 if the result was truncted to give \s-1OBJ,\s0 and undef if it is unknown whether \s-1OBJ\s0 is the exact result. .IP "\fI_gcd(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_gcd(OBJ1, OBJ2)" Return the greatest common divisor of \s-1OBJ1\s0 and \s-1OBJ2.\s0 .PP \fIBitwise operators\fR .IX Subsection "Bitwise operators" .PP Each of these methods may modify the first input argument. .IP "\fI_and(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_and(OBJ1, OBJ2)" Return bitwise and. If necessary, the smallest number is padded with leading zeros. .IP "\fI_or(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_or(OBJ1, OBJ2)" Return bitwise or. If necessary, the smallest number is padded with leading zeros. .IP "\fI_xor(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_xor(OBJ1, OBJ2)" Return bitwise exclusive or. If necessary, the smallest number is padded with leading zeros. .PP \fIBoolean operators\fR .IX Subsection "Boolean operators" .IP "\fI_is_zero(\s-1OBJ\s0)\fR" 4 .IX Item "_is_zero(OBJ)" Returns a true value if \s-1OBJ\s0 is zero, and false value otherwise. .IP "\fI_is_one(\s-1OBJ\s0)\fR" 4 .IX Item "_is_one(OBJ)" Returns a true value if \s-1OBJ\s0 is one, and false value otherwise. .IP "\fI_is_two(\s-1OBJ\s0)\fR" 4 .IX Item "_is_two(OBJ)" Returns a true value if \s-1OBJ\s0 is two, and false value otherwise. .IP "\fI_is_ten(\s-1OBJ\s0)\fR" 4 .IX Item "_is_ten(OBJ)" Returns a true value if \s-1OBJ\s0 is ten, and false value otherwise. .IP "\fI_is_even(\s-1OBJ\s0)\fR" 4 .IX Item "_is_even(OBJ)" Return a true value if \s-1OBJ\s0 is an even integer, and a false value otherwise. .IP "\fI_is_odd(\s-1OBJ\s0)\fR" 4 .IX Item "_is_odd(OBJ)" Return a true value if \s-1OBJ\s0 is an even integer, and a false value otherwise. .IP "\fI_acmp(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_acmp(OBJ1, OBJ2)" Compare \s-1OBJ1\s0 and \s-1OBJ2\s0 and return \-1, 0, or 1, if \s-1OBJ1\s0 is less than, equal to, or larger than \s-1OBJ2,\s0 respectively. .PP \fIString conversion\fR .IX Subsection "String conversion" .IP "\fI_str(\s-1OBJ\s0)\fR" 4 .IX Item "_str(OBJ)" Return a string representing the object. The returned string should have no leading zeros, i.e., it should match \f(CW\*(C`^(0|[1\-9]\ed*)$\*(C'\fR. .IP "\fI_as_bin(\s-1OBJ\s0)\fR" 4 .IX Item "_as_bin(OBJ)" Return the binary string representation of the number. The string must have a \&'0b' prefix. .IP "\fI_as_oct(\s-1OBJ\s0)\fR" 4 .IX Item "_as_oct(OBJ)" Return the octal string representation of the number. The string must have a '0x' prefix. .Sp Note: This method was required from Math::BigInt version 1.78, but the required \&\s-1API\s0 version number was not incremented, so there are older libraries that support \s-1API\s0 version 1, but do not support \f(CW\*(C`_as_oct()\*(C'\fR. .IP "\fI_as_hex(\s-1OBJ\s0)\fR" 4 .IX Item "_as_hex(OBJ)" Return the hexadecimal string representation of the number. The string must have a '0x' prefix. .PP \fINumeric conversion\fR .IX Subsection "Numeric conversion" .IP "\fI_num(\s-1OBJ\s0)\fR" 4 .IX Item "_num(OBJ)" Given an object, return a Perl scalar number (int/float) representing this number. .PP \fIMiscellaneous\fR .IX Subsection "Miscellaneous" .IP "\fI_copy(\s-1OBJ\s0)\fR" 4 .IX Item "_copy(OBJ)" Return a true copy of the object. .IP "\fI_len(\s-1OBJ\s0)\fR" 4 .IX Item "_len(OBJ)" Returns the number of the decimal digits in the number. The output is a Perl scalar. .IP "\fI_zeros(\s-1OBJ\s0)\fR" 4 .IX Item "_zeros(OBJ)" Return the number of trailing decimal zeros. The output is a Perl scalar. .IP "\fI_digit(\s-1OBJ, N\s0)\fR" 4 .IX Item "_digit(OBJ, N)" Return the Nth digit as a Perl scalar. N is a Perl scalar, where zero refers to the rightmost (least significant) digit, and negative values count from the left (most significant digit). If \f(CW$obj\fR represents the number 123, then \&\fI_digit($obj, 0)\fR is 3 and \fI_digit(123, \-1)\fR is 1. .IP "\fI_check(\s-1OBJ\s0)\fR" 4 .IX Item "_check(OBJ)" Return a true value if the object is \s-1OK,\s0 and a false value otherwise. This is a check routine to test the internal state of the object for corruption. .SS "\s-1API\s0 version 2" .IX Subsection "API version 2" The following methods are required for an \s-1API\s0 version of 2 or greater. .PP \fIConstructors\fR .IX Subsection "Constructors" .IP "\fI_1ex(N)\fR" 4 .IX Item "_1ex(N)" Return an object representing the number 10**N where N >= 0 is a Perl scalar. .PP \fIMathematical functions\fR .IX Subsection "Mathematical functions" .IP "\fI_nok(\s-1OBJ1, OBJ2\s0)\fR" 4 .IX Item "_nok(OBJ1, OBJ2)" Return the binomial coefficient \s-1OBJ1\s0 over \s-1OBJ1.\s0 .PP \fIMiscellaneous\fR .IX Subsection "Miscellaneous" .IP "\fI_alen(\s-1OBJ\s0)\fR" 4 .IX Item "_alen(OBJ)" Return the approximate number of decimal digits of the object. The output is one Perl scalar. This estimate must be greater than or equal to what \f(CW\*(C`_len()\*(C'\fR returns. .SS "\s-1API\s0 optional methods" .IX Subsection "API optional methods" The following methods 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: .PP \fISigned bitwise operators.\fR .IX Subsection "Signed bitwise operators." .PP Each of these methods may modify the first input argument. .IP "\fI_signed_or(\s-1OBJ1, OBJ2, SIGN1, SIGN2\s0)\fR" 4 .IX Item "_signed_or(OBJ1, OBJ2, SIGN1, SIGN2)" Return the signed bitwise or. .IP "\fI_signed_and(\s-1OBJ1, OBJ2, SIGN1, SIGN2\s0)\fR" 4 .IX Item "_signed_and(OBJ1, OBJ2, SIGN1, SIGN2)" Return the signed bitwise and. .IP "\fI_signed_xor(\s-1OBJ1, OBJ2, SIGN1, SIGN2\s0)\fR" 4 .IX Item "_signed_xor(OBJ1, OBJ2, SIGN1, SIGN2)" Return the signed bitwise exclusive or. .SH "WRAP YOUR OWN" .IX Header "WRAP YOUR OWN" 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: .PP .Vb 1 \& use Math::BigInt; .Ve .PP by this: .PP .Vb 1 \& use Math::BigInt lib => \*(Aqyourlib\*(Aq; .Ve .PP This way you ensure that your library really works 100% within Math::BigInt. .SH "LICENSE" .IX Header "LICENSE" This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Original math code by Mark Biggar, rewritten by Tels in late 2000. .IP "\(bu" 4 Separated from BigInt and shaped \s-1API\s0 with the help of John Peacock. .IP "\(bu" 4 Fixed, speed-up, streamlined and enhanced by Tels 2001 \- 2007. .IP "\(bu" 4 \&\s-1API\s0 documentation corrected and extended by Peter John Acklam, .SH "SEE ALSO" .IX Header "SEE ALSO" Math::BigInt, Math::BigFloat, Math::BigInt::GMP, Math::BigInt::FastCalc and Math::BigInt::Pari.