@@ -9,8 +9,10 @@ The file NEW lists only the changes for the latest version.
##############################################################################
Math::BigInt::Calc:
+
2001-07-09 v0.06 Tels
* first release
+
2001-07-15 v0.07 Tels
* applied Philip Newtons spelling and doc patch(s)
* accidentally had the old, slow mul() code in. Oups.
@@ -18,28 +20,38 @@ Math::BigInt::Calc:
* also the speedup in mul() occurs with $x having lots of zeros, not $y.
* first argument is always classname, so removed checks and shift
* shift in base ten by _lsft() and _rsft()
+
2001-07-15 v0.08 Tels
* fixed bug in mul() shortcut
+
2001-07-20 v0.09 Tels
* don't use warnings for older Perls
+
2001-08-24 v0.10 Tels
* no longer export anything, ignore import calls
+
2001-09-07 v0.11 Tels
* automatically USE_MUL or USE_DIV
+
2001-10-03 v0.12 Tels
* _div: 99999 => $BASE-1 ($MAX_VAL), that made some div's fail if $BASE != 5
+
2001-10-23 v0.13 Tels
* better detection of BASELEN by matching against expected pattern
+
2001-11-04 v0.14 Tels
* added _mod() for faster $x % $y
+
2001-11-11 v0.15 Tels
* added _dec() and _inc() for much faster $x++ and $x--
+
2001-11-19 v0.16 Tels
* fixed comments a bit
* finished _mod() when $y < $BASE and $BASE % $y != 0 and $BASE % $y != 1
* streamlined _mod() loops a bit
* added _pow() for faster bpow()
* small fix to make 5.005_03 happy ($x = shift @prod vs $x = shift @prod || 0)
+
2001-12-06 v0.17 Tels
* added _sqrt() for more speed
* _sqrt() shortcut for small (< $BASE) numbers for better performance
@@ -50,66 +62,84 @@ Math::BigInt::Calc:
* streamlined _acmp()
* cap of 5 for BASE for UTS and UNICOS/Cray
* better test to find out what BASE should be (use +0.0 to force floats)
+
2001-12-20 v0.18 Tels
* added _as_hex() and _as_bin() with 16 bit chunks
* from_bin() now uses oct() and 16 bits per iteration
* removed needless return statements
+
2001-12-23 v0.19 Tels
* first working version of using two different bases: one for mul/div, the
other for all other ops, including converting via _to_large()/_to_small()
+
2002-01-07 v0.20 Tels
* better detection of higher-int-only base (but disabled due to failures)
* streamlined converting
* turned dual-basis off by default (now 7-7 on 32 bit and 9-9 on most 64 it)
* _str() uses int() on first part to avoid '0000' instead of '0'
+
2002-02-10 v0.22 Tels
* _sqrt1() => _sqrt() (oups)
* much better guess for _sqrt() resulting in faster sqrt
* added _fac()
+
2002-02-24 v0.23 Tels
* from_bin() repack input and use from_hex(): twice as fast
+
2002-02-27 v0.24 Tels
* streamlined _mod() shortcuts
* _div() has shortcut if $y is very small
+
2002-03-03 v0.25 Tels
* started _square() (not done yet)
+
2002-03-17 v0.26 Tels
* a fix in _rsft() that left empty array instead of (0)
* a fix in _sub(): early out made -1 + 100000000001 == 0 (if length($y) > 8)
+
2002-05-30 v0.28 Tels
* added _modinv(), _modpow() (not yet implemented)
+
2002-06-09 v0.29 Tels
* filled in _modpow()
+
2002-06-10 v0.30 Tels
* undef mul/div in case Calc.pm get's loaded twice
* fix in _as_hex() and _as_bin() for older Perls
* speedups in _pow() and _modpow()
+
2002-08-13 v0.31 Tels
* _acmp() no longer calls _len() => tad faster
* some cleanup of old code, added some more comments
+
2002-08-21 v0.32 Tels
* fixed bug in _rsft() that did not set result to 0 in some cases
* _modinv() now works, thanx to the all-positive algorithm
* much more tests in bigintc.t (taken over from FastCalc)
+
2002-09-09 v0.33 Tels
* _fac() keep $n as scalar if possible
* test for when to USE_MUL or not was inverted
* _mul() is about 6 times faster if $y is small and $x is big
+
2002-09-27 v0.34 Tels
* fixed bug in mul_use_div() shortcut that used * $RBASE instead of / $MBASE
* $caught & 1 != 0 vs ($caught & 1) != 0 (changed to $caught != 2)
* $i %= $MBASE does not work on ARM (v5.003), so make it $i -= $car * $MBASE
* removed unused LEN_CONVERT code (smaller memory footprint)
+
2003-07-06 v0.35 Tels
* fixed a bug in _floor() which caused ffloor(0.1234567) to fail.
(Thanx to cpan@ali.as for finding it and sending a fix/testcases)
* make _as_hex() and _as_bin() handle 0, and make them faster for very
short numbers (less than BASE_LEN digits)
+
2003-08-31 v0.36 Tels
* fixed a bug in div_use_div() that computed remainder wrong if X == X and
X was very large
* fixed a off-by-one error discovered with mbi_rand.t in _div_use_XXX()
(one internal in $x overflowed, thus the wrong computation)
+
2003-12-11 v0.37 Tels
* implemented _log_int() with a simple and fast "iterative" method
* fixed bug in _root(): int() rounds sometimes wrong, so use sprintf()
@@ -125,6 +155,7 @@ Math::BigInt::Calc:
* _as_bin() used %b, which was not known to v5.5.3 - workaround that
* implemented _log_int(), which is simple and very fast
* implemented the missing pieces for _root() (which is quite fast)
+
2003-12-30 v0.38 Tels
* guess _log_int() result based on $base if $base < $BASE
* _pow() handle cases 0 ** Y, 1 ** Y, X ** 0 and X ** 1
@@ -132,8 +163,10 @@ Math::BigInt::Calc:
* _root() was wrong for numbers like 9 (0b1001) because they start with
the pattern /^0b1(0+)/ (missing '$' in regexp) and after fixing this
it was dead slow for large numbers.
+
2004-01-25 v0.39 Tels (not released)
* _zeros(0) is 0, not 1
+
2004-03-12 v0.40 Tels
* added: api_version(), _ten(), _two(), _is_ten(), _is_two(), _gcd()
* streamlined: is_foo() methods
@@ -143,62 +176,83 @@ Math::BigInt::Calc:
than the positive one caused an error due to cutting instead padding
* _ior(): forgot to calculate the proper sing of result, making, for
instance, 30 | -4 go wrong
+
2004-04-05 v0.41a Tels (not released)
* removed the unused integer-detection code and combined the two BEGIN blocks
+
2004-07-30 v0.41 Tels
* from_hex() convert 28 bits (vs 16) at a time, faster (helps from_bin(), too)
* potential bug in padding with '0' in _digit()
* fixed undef warnings in fceil(0.222222222222...) (thanx kenny!)
+
2004-10-10 v0.42 Tels
* fix critical bug in _from_hex() with parts that were to big for one part
(introduced in v1.72, thanx Mark Lakata for finding it!)
+
2005-01-01 v0.44 Tels
* small cleanups
* shortcut for numbers of same length in _div, where X > Y
+
2005-03-20 v0.45 Tels
* fix the div() shortcut for short numbers to actually work
+
2005-03-29 v0.46 Tels
* avoid crash in FastCalc by making $BASE and $BASE_LEN use vars qw//;
+
2005-05-17 v0.47 Tels
* remove shortcut in div(), it wasn't working properly
+
2007-01-27 v0.48 Tels
* support for octal numbers
+
2007-04-16 v0.49 Tels
* API version 2.0 support: add _1ex(), _alen()
* make _fac() about twice as fast
+
2007-05-05 v0.50 Tels
* speed up _mul() by "use integer;"
* we do not need to remove zeros after mul()
* implement an alternative algorithm for _fac()
+
2007-05-30 v0.51 Tels
* use CORE::hex() instead of hex() to help bigint/bignum/bigrat
* use 9 digit parts on 64bit integer or long double systems
+
2007-09-16 v0.52 Tels
* fix 64bit ints on Perl v5.8.0 (thanx zefram)
##############################################################################
Math::BigInt::CalcEmu:
+
2003-12-26 v0.01 Tels
* first version, taken over all the code from BigInt
+
2003-12-30 v0.02 Tels
* the code in Calc::_root() uses now sprintf(), but the one in Emu was not
+
2004-01-13 v0.03 Tels
* $VERSION was overriding the $VERSION from MBI (Thanx Gisle Aas!)
+
2004-03-12 v0.04 Tels
* removed unnec. emulation routines (all except _signed_foo)
##############################################################################
Math::BigInt::Scalar:
+
2001-07-09 v0.04 Tels
* first release
+
2001-07-15 v0.05 Tels
* first argument is always classname, so removed checks and shift
+
2001-07-20 v0.06 Tels
* don't use warnings for older Perls
+
2001-08-24 v0.10 Tels
* no longer export anything, ignore import calls
+
2002-01-07 v0.11 Tels
* fixed version
* added DESCRIPTION section to stop pod2man complaining
@@ -207,14 +261,21 @@ Math::BigInt::Scalar:
##############################################################################
Math::BigFloat:
+
2001-02-18 1.00: started work
+
2001-02-22 1.01: new() and bstr() work now (sort of)
+
2001-02-24 1.02: add()/sub() should work now
+
2001-03-06 1.03: layed more foundations (mul() etc)
+
2001-03-27 1.04: bmul/bdiv/cmp work now, better _norm()
+
2001-03-31 1.05: fixed bstr() and bsstr()
added AUTOLOAD for fxxx() to work as well as bxxx()
enhanced and fixed testsuite for mul/cmp/add/new
+
2001-04-05 1.06: bstr() returns NaN for NaN's
renamed _norm to bnorm, added it to AUTOLOAD for compatibility
fixed bug Math::BigFloat->new(Math::BigInt->new(3));
@@ -222,31 +283,38 @@ Math::BigFloat:
bdiv() works now with precision
precision()
doc about mixing different objects in overloaded math
+
2001-04-07 1.07: bug in bstr() for 0.xxx style numbers, as well as for "-xxx"
babs(), bneg(), bint() work now
empty stubs for bsqrt(), bround() and bmod()
exponent(), mantissa(), parts() work now as expected
+
2001-04-18 1.08: exponent(), mantissa() and parts() now return BigInt's
bnorm: 0Ey => 0E1 (was wrongly 0E0)
fixed is_zero()
added bround() and bfround() (only truncate mode)
fixed bug in bstr() for 1.203E-2 style numbers (Thanx Tom!)
+
2001-04-23 1.09: length() in list context return length of mantissa & exponent
bug in bstr() for '0.x' style strings
added bsqrt()
workaround for Perl v5.6.0 overload-bool bug (via MBI)
fixed rounding
+
2001-05-07 1.10: Tom's round fixes (minus one nit)
new: .xxx, -.xxx, +.xxx etc are valid inputs, while
'.', 'x x x' and 'Exxx' are now invalid
finally got rid of C&P of overload section and clone()
+
2001-05-09 1.11: bug bcmp() (1e-08 was < 0, aka fractions were broken)
+
2001-05-11 1.12 Tels
* taken over testsuite from John P.
* added tests for compare with fraction
* fixed fcmp/fround/ffround
* added accuracy/precision/fallback/round_mode
* bsstr('NaN') returned 'NaNeNaN'
+
2001-06-09 1.13 Tels:
* adjusted fdiv() so that it now works proper with old testcases
* (except a few nits, see testsuite and ACCURACY)
@@ -256,6 +324,7 @@ Math::BigFloat:
* fixed fpow(), added tests for it
* hexadecimal integer input (0xdeadbeef)
* is_one() for -1 was wrongly true, tests for is_one()
+
2001-06-13 1.14 Tels:
* accuracy/precision rounding after fdiv() was missing
* binary integer input (0b01110 etc)
@@ -267,8 +336,10 @@ Math::BigFloat:
* $x->bpow($y) for negative $y was unfinished
* added is_inf(), binf() and some support for +-inf in new(), bsstr() etc
* added tests for is_odd(), is_even(), _set() and is_zero(), is_inf(), bsstr()
+
2001-06-15 v1.15 Tels
* added bfloor(), bceil()
+
2001-07-09 v1.16 Tels
* is_positive(), is_negative()
* various pod fixes (overlong =item, spelling erorrs etc)
@@ -276,42 +347,51 @@ Math::BigFloat:
* infinity support for fcmp(), fpow()
* nailed the bug in fdiv() that caused fsqrt() to fail. fsqr() works now, too.
* more tests
+
2001-07-15 v1.17 Tels
* applied Philip Newtons spelling and doc patch(s)
* added bone()
* tests for bnan() and bone()
+
2001-08-02 v1.19 Tels
* 123/+-inf => 0, test for that and -1,0 / NaN => NaN
* +123 / 0 => +inf, -123 / 0 => -inf (was missing in MBF)
* fixed +-inf handling in bacmp/bcmp/bsub/badd/bdiv and tests for that
* padd bstr() output of numbers with set A or P
* remove bfloat() (Math::BigInt->bfloat() did not work, anyway, see bint())
+
2001-08-03 v1.20 Tels
* streamlined bcmp
* drop leading '+' for inf
+
2001-09-03 v1.21 Tels
* serious bug in bcmp() caused 1.5 to be greater than 2. Yikes!
* bcmp() did not only return -1,0,1 and undef but other values, too
* new('inf') produced NaN (was expecting '+inf')
* exponent(), mantissa() & parts() failed or returned scalars for inf,-inf,NaN
* include finf in AUTOLOAD list
+
2001-10-03 v1.22 Tels
* Quite a lot of rounding fixes
* $x->bnorm() is 4 times faster if $x == 0
* $x->bround($n) is 43 times faster if $n > $x->{_a} (no-op)
* added as_number()
+
2001-10-05 v1.23 Tels
* fixed facmp() (was broken the same way as fcmp())
* more rounding fixes from John P.
+
2001-11-11 v1.24 Tels
* bacmp() fix for +-inf
* streamlined new()
* faster finc()/fdec()
+
2001-11-18 v1.25 Tels
* streamlining fixes in new() were missing
* further streamlining in new() for 12345e1234 cases (fraction part empty)
* added $rnd_mode support for compatibility
* replaced the 'laber schwad blah blah' pod section by a pointer to MBI
+
2001-12-06 v1.26 Tels
* fneg() failed (now hand up to MBI)
* frsft() and flsft() were no aliases to brsft() and blsft()
@@ -323,6 +403,7 @@ Math::BigFloat:
* make fsqrt() subclass proof by using $self instead of Math::BigFloat
* bzero(), bone(): take additional A and P and store 'em
* bnan(), binf(): clear A and P
+
2002-01-06 v1.27 Tels
* overload for log() and flog()/blog()
* bzero()/bone() handling of A & P was broken
@@ -332,17 +413,21 @@ Math::BigFloat:
* fsqrt() didn't modify $x sometimes, but returned a new reference
* fsqrt(): calc 4 more digits for rounding, not 1 (endless looping otherwise)
* fmod() now actually works
+
2002-02-10 v1.27 Tels (forgot to increase version)
* ffac()
* various: disable Math::BigInt::upgrade to avoid deep recursion
+
2002-02-16 v1.28 Tels
* fixed use Math::BigFloat ':constant';
* fixed flog() function to calc right result, honour rounding-globals
+
2002-02-24 v1.29 Tels
* overload for 'log' now inherited by BigInt
* _binf(), _bnan(), _bone() and _bzero() instead of longer bone() etc
* inf/NaN fixes from v1.51 were missing for BigFloat
* bdiv() upgrades if applicable
+
2002-02-25 v1.30 Tels
* bug in bsub() with not rounding when $x->bsub(0) was also in MBF
* bcmp() and bacmp() 5 times faster due to numify() (might have now impose a
@@ -354,16 +439,21 @@ Math::BigFloat:
* optimized as_number (nearly twice as fast)
* $x->badd(0) forgot to round $x
* downgrade and upgrade are valid methods for inheritance
+
2002-03-03 v1.31 Tels
* bpow() can handle second arguments beeing non-integer (f.i. 2 ** 0.2)
* $x->bpow(0.5) optimized to $x->bsqrt();
+
2002-05-19 v1.32 Tels
* upgrade used badd() instead of bmul() inside bmul()
* bpow() now uses slower, but more correct way for fractions (this needs work)
+
2002-06-09 v1.33 Tels
* import() fixed for older Perls
+
2002-06-10 v1.34 Tels
* upgrade used badd() instead of bmul() inside bmul() (again! arg!)
+
2002-07-07 v1.35 Tels
* bfround() used accidentally BigInt math; is now about 5.6 times faster for
small numbers
@@ -371,6 +461,7 @@ Math::BigFloat:
* doc for accuracy()/precision()
* $x->bmod() was not modifying $x in place when returning NaN/inf/-inf
* avoid unec. calls to objectify() for binary op's
+
2002-08-13 v1.36 Tels
* as_hex() and as_bin() work now at least for inf, NaN and integers
* fixed bsstr() (and thus also numify()) for negative numbers - Ouch!
@@ -378,8 +469,10 @@ Math::BigFloat:
when $d > $a
* numify() returned '+inf' instead of 'inf'
* (more) tests for bsstr(), numify(), as_hex(), as_bin
+
2002-08-20 v1.37 Tels
* bcmp()/bacmp() upgrade now if requested
+
2002-09-08 v1.38 Tels
* fix that bsqrt() would hang for certain inputs. Instead of using Newton's,
we now rely on the fact that sqrt(x*y) = sqrt(x) * sqrt(y) by setting y to
@@ -389,6 +482,7 @@ Math::BigFloat:
instead of beeing equivalent to $x->bsqrt(undef)
* ditto for $x->bpow($y,0), $x->blog($base,0) and $x->bdiv($y,0)
* use File::Spec was needless, since it was required later on again
+
2002-11-03 v1.39 Tels
* $x->bpow($y,0), $x->blog($base,0) and $x->bdiv($y,0) were still not doing
the right thing and no tests caught it *sigh*
@@ -414,13 +508,16 @@ Math::BigFloat:
* trap_nan/trap_inf really croak on any attempt to create an NaN/inf
* spellings of Bigint => BigInt
* simplify config() by using SUPER::config()
+
2003-07-06 v1.39 Tels
* $x->blog($base) can handle a $base which is a Math::Bigint
* replace die() with Carp::croak
+
2003-09-23 v1.40 Tels
* bstr(): removed unnec. BigInt math and inlined is_zero() => great speedup
(10% to factor 6.5 depending on input)
* replace $self->_one() by $self->bone()
+
2003-12-11 v1.41 Tels
* flog(): 0.5, 0.25, 0.125, 2, 4 and 8 were not scaled properly back to
1, instead they remained 0.5 and 2, respectively. This was a '<' vs.
@@ -432,21 +529,25 @@ Math::BigFloat:
2, 10 and 0.1 slightly faster. This also helps log($x,2) and log($x,10).
* bfac() slightly faster for small arguments
* downgrading to bigint failed for .2e2 (produced 200 vs. 20)
+
2003-12-30 v1.42 Tels
* ffac(inf) is inf, not NaN
* flog() calculate integer result first, and if it fits, return it
this makes it much faster in case the result is a perfect integer
* require (instead of use) Exporter
* froot() calculates an integer result first, and it if fits, returns it
+
2004-01-13 v1.43 Tels
* small fixes in AUTOLOAD
* delete $x->{_a} vs. $x->{_a} = undef to save memory
+
2004-03-12 v1.44 Tels
* bpow() computed -X ** Y wrong for Y that are odd
* use $HALF instead of 0.5 to speed up broot()
* use Calc instead of BigInt for parts, that makes it roughly 2x faster
it also saves memory (419 vs. 767 bytes per (small number) object)
* bmod() did needlessly test for NaN arguments twice
+
2004-07-30 v1.45 Tels
* simple inherit bsub() from BigInt, also fixes bsub() failing under
$x -= $x - Thanx Peter J. Acklam!
@@ -454,13 +555,16 @@ Math::BigFloat:
* bfround() and bround() are about 10% faster when going via Math::BigInt's
bround() due to constructing a fake BigInt instead of going via ->new()
* fixed undef warnings in bpow(0,$y) ($y non-integer) (thanx kenny!)
+
2004-08-13 v1.46 Tels
* blog(10,10) ($x == $y) returned '1.0000...' instead of '1'
+
2004-10-10 v1.47 Tels
* inf/NaN fixes for bpow()
* eliminate the need for _zeros() in new() (speed-up for GMP et. al.)
* eliminate _is_zero() in new() (small speed up)
* added shortcut for simple numbers in new() (speed up)
+
2005-01-01 v1.48 Tels
* use new interface to _scale_a() and _scale_p() in BigInt
* add bneg() and inline is_zero() in it, making it 1.6 times faster
@@ -468,26 +572,32 @@ Math::BigFloat:
makes some ops (bsstr(), bneg etc) about 2% faster for small numbers
* use MBI::_register_callback() to get notified of lib changes
* bgcd()/blcm() never worked, so fix them for integers and add tests
+
2005-03-20 v1.49 Tels
* remove dependecy on Scalar::Util in bdiv()
* bdiv() cache result of "!$y->is_one()" for wantarray case to make
($res,$rem) = $x->bdiv($y); about 10% faster
+
2005-03-29 v1.50 Tels
* fix rounding doc, add notes about prevision vs. accuracy
* set FastCalc as default (we still use whatever MBI uses)
+
2005-04-10 v1.51 Tels
* fix new() to work with Math::BigInt::Pari
+
2007-01-27 v1.52 Tels
* fix brsft() and bpow() in list context only return on number (bug #21413)
* make as_int() return a BigInt, too (not just as_number()) (bug #21412)
* add as_oct()
* bpow(): handle negative X and negative Y (instead of returning NaN)
+
2007-03-04 v1.53 Tels
* fix #25144: [PATCH] Math::BigFloat->new considers any reference a BigInt
(Thanx mschwern!)
* fix bug #13866: NaN (in bignum queue)
* fix bug #21586: Incorrect result when comparing with NaN
* fix bug #15896: "==" overloading is broken for "NaN"
+
2007-04-09 v1.54 Tels
* fix bug #21747: Re: weirdity in bignum... (powers and high precision):
infinite loops for blog() (and consequently bpow()) if you requested
@@ -500,19 +610,23 @@ Math::BigFloat:
This makes computing _log(10) much faster, so that computing blog(N) is
about a factor of 5 faster when N >= 10 or N <= 0.1
* add bexp()
+
2007-04-16 v1.55 Tels
* make bexp() much faster (esp. under GMP) by caching the first coefficients
and rewriting the inner loop
* support "try" and "only" in import()
+
2007-05-05 v1.57 Tels
* add bnok() method (n over k)
* add all the missing modify() hooks
+
2007-06-30 v1.58 Tels
* remove Exporer from @ISA
* support config('lib') as shortcut for config()->{lib}
* add bpi(), bcos(), bsin(), batan(), batan2() methods
* add bmuladd()
* streamline the is_xxx() and copy() methods
+
2008-04-20 v1.60 Tels
* fix #34459: bsqrt() breaks on floats with enough digits (Thanx Niko Tyni!)
* fix #35238: batan2() handles inf/+inf wrong
@@ -521,31 +635,41 @@ Math::BigFloat:
##############################################################################
Math::BigInt:
+
2000-11-13 v1.02 Tels
fixed sub and mul (sort of)
found out that "$wanted = shift || return bzero()" causes a call to numify,
testing for undefined fixes this problem (but might waste more time for
a new(0), will save time on average.
+
2000-11-14 v1.03 Tels
x**0 => 1 (instead of x)
fixed bigintpm to include bpow, binc, bdec, new() test
+
2000-11-15 v1.04 Tels
fixed bigintpm to test '++' and '--' properly
done div, fixed mul/bpow (13 tests remain)
+
2000-11-16 v1.05 Tels
8 tests remain
new copies _all_ fields, not only Math::Bigint ones
+
2000-11-19 v1.06 Tels
7 tests remain
bgcd accepts lists, added blcm
+
2000-11-20 v1.07 Tels
objectify fixed to not make copies and work with subclasses
+
2000-11-22 v1.08 Tels
fixed all but one test (band bior bxor etc)
+
2000-11-23 v1.09 Tels
fixed bug in bmul (and thus bpow) (self multiply works now)
+
2000-11-24 v1.10 Tels
finally made it Math::BigInt (w/o trailing 's')
+
2001-02-14 v1.11 Tels (first release)
* fixed bug in band(), bxor(), etc that used badd($x, fixed_number_here);
* since subclasses might not be happy with fixed numbers, make sure we pass
@@ -553,6 +677,7 @@ Math::BigInt:
* fixed bug in band/bxor/bior which destroyed second argument
* bxor/band/bior work now correctly for subclasses
* ++ and -- are now a tad (ca 5%) faster
+
2001-02-16 v1.12 Tels
* accidentally dropped self-multiply test in bigintpm.t
* fixed bug in overloading cmp
@@ -567,8 +692,10 @@ Math::BigInt:
the '+', adapted all the tests, changed the doc, etc.
BigInts behave now transparently like build-in scalars in integer/string
context ;o)
+
2001-02-18 v1.13 Tels
* got rid of duplicated copy() code in new()
+
2001-02-21 v1.14 Tels
* overload +=, -=, *= and /= for about 20-30% more speed if both args have
roughly same length
@@ -576,6 +703,7 @@ Math::BigInt:
an O(1) case instead of O(N)
* fixed (non-critical) bug that caused objectify in numify/bool/stringify to
create scratch objects from undef params.
+
2001-02-24 v1.15 Tels
* $x / $x is now a lot faster (more O(1) than O(N))
* 10 ** $x is now a lot faster (more O(N/5) instead of O(N))
@@ -584,6 +712,7 @@ Math::BigInt:
* -a % b = +c (was -c) to be compatible with perl
* added $x->length() and test for it; fixed _digits() (was off by 1)
* objectify() was not exported, added tests for objectify()
+
2001-03-09 v1.16 Tels
* Math::BigInt::badd(4,5) and Math::SomeChildOfBI->badd(4,5) work now
* '$x = scalar (**|%|+|-|*|\) $object;' failed (was not tested, either)
@@ -596,22 +725,27 @@ Math::BigInt:
* tests after "use Math::BigInt :constant" were screwed due to not using eval
* $x->numify() (for $array[$x] = 0; etc) is much faster now
* added caveat documentation for $x = -$x; and $x *= string1 operator string2;
+
2001-03-24 v1.20 Tels
* added: is_nan()
* bug in bmod/bdiv, I forgot some cases with negatives. Thanx to Bruce Fields!
* documented ':constant' and eval() crash on Perl 5.00x
* documented BigInts behaviour of bmod/bdiv and use integer
+
2001-03-30 v1.21 Tels
* bool() works now under 5_005
* bug in bsub where numbers with at least 6 trailing digits after any op failed
+
2001-04-05 v1.22 Tels
* documented Peters OS/390 patch/changes (fix was in for quite some time)
* fixed bug Math::BigInt->new(Math::BigFloat->new(3));
* objectify() with other objects than BigInt as further args, copy() etc
* $x->digit($n) to query fast value of Nth digit
* as_number()
+
2001-04-07 v1.23 Tels
* spelling errors in pod
+
2001-04-23 v1.3 Tels
* added (compatible to MBF) mantissa(), exponent() & parts() as well as tests
* _trailing_zeros()
@@ -621,6 +755,7 @@ Math::BigInt:
* added is_valid to testsuite to see whether invalid objects are created
* added bsqrt()
* workaround coredump bug in bool() for v5.6.1
+
2001-05-08 v1.31 Tels
* _ between digits now accepted, ' ' no longer valid inside (but at front/end)
* Exxx is NaN, and no longer produces warning
@@ -629,8 +764,10 @@ Math::BigInt:
* fixed overload (w/ _swap/copy), subclasses can inherit it easily
* removed clone()
* added bsstr()
+
2001-05-11 v1.32 Tels
* added accuracy/precision/fallback/round_mode
+
2001-06-09 v1.33 Tels
* bround() no longer uses 10 ** $pad and is thus much faster when rounding up
* fixed and added rounding benchmark (did time bmul instead bround)
@@ -642,14 +779,17 @@ Math::BigInt:
* $x->accuracy(), $x->precision() actually round $x to the set value
* tests for is_one()
* hexadecimal integer input (0xcafebabe etc)
+
2001-06-13 v1.34 Tels
* binary integer input (0b01110 etc)
* fixed: '-0x0' left '-0'
* added is_inf(), binf() and some support for +-inf in new(), bsstr() etc
* added tests for is_odd(), is_even(), _set() and is_zero(), is_inf(), bsstr()
+
2001-06-15 v1.35 Tels
* added bfloor(), bceil()
* fixed bior(), bxor(), band() for $x->bxxx(NaN,0), added modify() to them
+
2001-07-04 v1.36 Tels
* is_positive(), is_negative()
* various pod fixes (overlong =item, spelling erorrs etc)
@@ -658,6 +798,7 @@ Math::BigInt:
* fixed tests for bacmp() (could never fail)
* removed internal _set() and tests for it
* +-inf handling in bcmp(), bpow()
+
2001-07-15 v1.37 Tels
* applied Philip Newtons spelling and doc patch(s)
* Benjamin Trott: _split() is faster for numbers that need no splitting
@@ -670,22 +811,27 @@ Math::BigInt:
* tests for bnan() and bone()
* Math::BigInt::Calc now determines biggest $BASE to use. Default should now
be 1e7 on most systems, giving 20% to 40% speedups.
+
2001-07-15 v1.38 Tels
* test for mul() shortcut
+
2001-08-02 v1.39 Tels
* fixed history (duh!)
* assign return values from $CALC back to $x->{value}
* fixed +-inf handling in a lot of places and tests for that
* band(), bxor() and bior() now work with negative inputs
* remove bint() (Math::BigFloat->bint() just DNDWIM and no sense, either)
+
2001-08-03 v1.40 Tels
* bxor(-$x,-$y) was broken (and not tested *sigh*)
* streamlined bcmp
* drop leading '+' for inf
* bxor(), band(), bior() with negative arguments don't get passed to lib
(makes it work with BitVect, Pari, GMP etc)
+
2001-08-08 v1.41 Tels
* fixed inf test (coredumps)
+
2001-09-03 v1.42 Tels
* bug in overload section causing performance losses in subclasses
* call $CALC->import() with list of libs
@@ -694,24 +840,29 @@ Math::BigInt:
* $x->bmod() did not modify $x, only returned result. Oups.
* new('inf') produced NaN (was expecting '+inf')
* exponent(), mantissa() & parts() failed or returned scalars for inf,-inf,NaN
+
2001-10-05 v1.43 Tels
* $x->bround($n) is 43 times faster if $n > $x->{_a} (no-op)
* Heaploads of rounding fixes (and tests)
* Test for 99999-bug in Calc
+
2001-11-04 v1.45 Tels
* tests run now in subclass, too
* bmod() can use _mod in lib
* lots of tests fixed (assumed wrong base etc) and added
* bpow() about 10-15% faster for small numbers (like 2 ** 150, 3 * 200 etc)
+
2001-11-11 v1.46 Tels
* binc(),bdec() use lib (via _inc(),_dec()) => faster (see BENCHMARK)
* avoid the unnec. rounding bsub()/binc()/bdec() (badd() already took care)
* made bsub() faster by removing the bneg() overhead from it
+
2001-11-18 v1.47 Tels
* added $rnd_mode support for compatibility
* two 'my $t = ... if ..;' cases to 'my $t; $t = ... if ...;'
* added overload for %=, |=, &= and ^= for more speed
* _split(): check for 1e2e3 and reject it
+
2001-12-06 v1.48 Tels
* fixed pod in many places
* bmod: use round(), not bround()
@@ -723,6 +874,7 @@ Math::BigInt:
* removed the EXPORT_OK except for objectify, _swap and bgcd/blcm
* bzero(), bone(): take additional A and P and store 'em
* bnan(), binf(): clear A and P
+
2002-01-07 v1.49 Tels
* as_hex() and as_bin() use 16 instead of 8 bits per iteration
* overload for log() and blog()
@@ -733,6 +885,7 @@ Math::BigInt:
* embedded _find_round_parameters into round(), streamlined both versions
* round() now uses string-add to make it almost twice as fast
* bnot() did round twice
+
2002-02-10 v1.50 Tels
* bfac() and hook for _fac() in libs
* documented sub-classing and auto-upgrade
@@ -742,19 +895,23 @@ Math::BigInt:
* Math::Big(Int|Float)->accuracy() clears precision, and vice versa
* small optimization in bdiv() regarding abs($x) < abs($y)
* brsft() for negative numbers in base 2 was completely wrong
+
2002-02-16 v1.51 Tels
* fixed bfround(-x) (f.i. 0.004->bfround(-2) resulted in 0.01, not 0.00)
* bfround(x) rounded at wrong place (off by one)
* calling bfround(x) rounded further and further instead of keeping result
* blog() upgrades if requested
* added doc stub for every public function
+
2002-02-24 v1.52 Tels
* hooks for _bin(), _bnan(), _bone() and _bzero()
* =head2 section for accuracy
+
2002-02-27 v1.53 Tels
* precisision typo
* fixed overlong pod =item
* added downgrade()
+
2002-03-03 v1.54 Tels
* really fixed overlong pod =item
* downgrade() and upgrade() with undef as argument didn't clear the variable
@@ -763,22 +920,28 @@ Math::BigInt:
* bpow() upgrades if second argument is non-integer
* objectify disable downgrade (for MBF)
* new() twice as fast due to shortcut simple numbers, save _split() & _round()
+
2002-03-17 v1.55 Tels
* :constant picks up binary/hexadecimal constants
* Math::BigInt->digit(123) works now
+
2002-03-17 v1.56 Tels
* documented config()
* simplified import() logic a bit
* changed some isa->($upgrade) => !$isa->($self);
+
2002-05-30 v1.57 Tels
* fixed objectify() to make "perl -Mbigrat -le 'print 1+2/3'" work
* added bmodpow() and bmodinv() as (not-working yet) stubs
+
2002-06-09 v1.58 Tels
* invalid inputs with two dot's (1.2.3 or 1..2 etc) are now really invalid
+
2002-06-10 v1.59 Tels
* pod fixes for bmodpow()/bmodinv()
* fix in as_hex() and as_bin() for older Perls
* speedups in bpow(), bmodin() and bmodpow()
+
2002-07-07 v1.60 Tels
* shortcuts to avoid calls to objectify for add/sub/mul/div/mod/pow/bcmp etc
* fix overloaded bcmp() so that the objectify()-avoidance kicks in
@@ -791,20 +954,24 @@ Math::BigInt:
* some binary ops (band/bxor/bior/bpow) were not properly rounding the result
to the requested A/P/R; the same ops also forgot to take $y into account
* doc for accuracy()/precision()
+
2002-08-13 v1.61 Tels
* tests for bsstr()/numify() with negative/special inputs
* bround() keeps $scale as scalar for speed and less problems
* fix for trailing newlines in input
* some doc fixes (especially return values of is_foo() methods)
* make testsuite so that it will pass under FastCalc easily
+
2002-08-21 v1.62 Tels
* bcmp()/bacmp() upgrade now if requested
* bmodinv() uses an all-positive algorithm, speeding it up by about 5-8%
and allowing to implement the same algorithm in Calc for factor 4 speedup
+
2002-09-08 v1.63 Tels
* bsqrt() did not modify $x but returned new object when lib does not have
a _sqrt() routine (BareCalc, BitVect and Pari are affected, Calc, FastCalc
and GMP were not)
+
2002-11-03 v1.64 Tels
* removed needless "my $c = ...;" statements in binf() and bnan()
* forgot () around "$x->{_f} & MB_NEVER_ROUND"
@@ -819,6 +986,7 @@ Math::BigInt:
* trap_nan/trap_inf really croak on any attempt to create an NaN/inf
* spellings of Bigint => BigInt
* _find_rounding_parameters(): set $a to undef if it is 0
+
2003-07-13 v1.65 Tels
* document that config() can set certain values
* replace die() with Carp::croak()
@@ -826,6 +994,7 @@ Math::BigInt:
faster, especially when under a different lib like GMP.
* Fixed the infinite recursion in bignum. See http://xrl.us/k6y
* fix handling of 0e999, 0e-999 etc
+
2003-09-01 v1.66 Tels
* document accepted inputs better
* fix wrong upgrade and undef-parameter handling in broot()
@@ -834,6 +1003,7 @@ Math::BigInt:
* warn if broot() cannot yet compute proper result
* remove needless _one(): 3% speedup for binc()
* remove needless _swap(): 1% (Calc) - 6% (GMP) speedup for overloaded math
+
2003-12-02 v1.67 Tels
* overload for cos/sin/exp/atan2 to make cos(Math::BigInt->new(...)) work
* implemented blog() with a simple and fast "iterative" method
@@ -851,6 +1021,7 @@ Math::BigInt:
* small change for overload::constant
* bfac(): do 0 or 1 check only if CALC cannot do _fac() (thus faster)
* removed a needless _copy in bmod() with negative arguments (slightly faster)
+
2003-12-26 v1.68 Tels
* bfac(inf) is inf, not NaN
* added alias names: as_int() (as_number()), is_pos(), is_neg() and doc
@@ -863,11 +1034,13 @@ Math::BigInt:
* bpow(): removed some now needless tests for 0 and 1: about 30% faster
for small numbers
* streamlined exponent() (parts() benefits from this, too)
+
2004-01-13 v1.69 Tels
* bacmp(+-$x,-inf) was wrong (Thanx William T. Morgan!)
* digit($x,$y) segfaulted under 5.6.1 if $y was a BigInt
* blog() was missing the modify() check (breaking MBI::Constant)
* delete $x->{_a} vs. $x->{_a} = undef to save memory
+
2004-03-12 v1.70 Tels
* bpow() computed -X ** Y wrong for Y that are odd
* 0 ** -Y => +inf (was NaN) due to 0 ** -Y => 1/0**Y => 1/0 => +inf
@@ -877,17 +1050,21 @@ Math::BigInt:
* fixed upgrading of blog() with base = undef (means: base e)
* make the synopsis actually runnable (Thanx Paul McCarthy)
* blcm(): handle a list of strings (instead one obj and some strings), too
+
2004-07-08 v1.71 Tels
* fixed bsub() failing under $x -= $x; Thanx Peter J. Acklam!
* _scan_for_nonzero() reuses length/stringform of $x and is thus faster, this
helps rounding if the number after the roundposition is '5'
+
2004-07-13 v1.72 Tels
* no changes
+
2004-10-10 v1.73 Tels
* overloading of <<= and >>= makes these ops about 10% faster and fixes the
problem that "$a <<= 2" would create a different object for $a to point to
* quite a lot of fixes for NaN/inf handling in bpow() (bmul already did it
right) - bug report by jeff at thekidders com and Hugo - Thank you!
+
2005-01-01 v1.74 Tels
* streamline _scale_a() and _scale_p() for more speed in rounding
* remove the now unnec. support for MB_NEVER_ROUND and {_f}, this
@@ -905,16 +1082,20 @@ Math::BigInt:
* is_positive(0) == 0, since 0 is neither positive nor negative
* streamline bmod() a bit
* fix blog() constructing arguments (broke Math::BigInt::Constant)
+
2005-03-20 v1.75 Tels
* use a trick to remove the dependency on Scalar::Util in bsub()
* fix atan2(), it did not preserve the order of arguments
(Thanx to Ambros & Zaxo for report and patch!)
+
2005-04-10 v1.76 Tels
* fix rounding doc, add notes about prevision vs. accuracy
* trap inf and -inf in new()
* load FastCalc as default
+
2005-05-17 v1.77 Tels
* bump version
+
2007-01-27 v1.78 Tels
* implement "try" and "only" as replacements for "lib"
* make 'use Math::BigInt lib => "foo"' warn if foo cannot be loaded and a
@@ -925,8 +1106,10 @@ Math::BigInt:
* fix bug perl #41050 - NaN returned when raising integer value to negative power
* add from_hex(), from_oct(), and from_bin()
* add as_oct()
+
2007-02-02 v1.79 Tels
* fix typos
+
2007-03-04 v1.80 Tels
* require Perl v5.6.2 as minimum
* fix bug #24969 (Can't use an undefined value as an ARRAY reference)
@@ -934,21 +1117,28 @@ Math::BigInt:
* fix bug #13866: NaN (in bignum queue)
* fix bug #21586: Incorrect result when comparing with NaN
* fix bug #15896: "==" overloading is broken for "NaN"
+
2007-03-16 v1.81 Tels
* no code change, just a package update
+
2007-04-09 v1.82 Tels
* use $CALC->_zeros() directly (instead _trailing_zeros()) to speed up
exponent() and mantissa()
* fix documentation that blsft() and brsft() default to base 2 (not 10)
* add bexp() and fix overloading for exp()
+
2007-04-16 v1.83 Tels
* bump version
+
2007-05-04 v1.84 Tels
* add bnok() method (n over k)
+
2007-05-05 v1.85 Tels
* bump version
+
2007-05-05 v1.86 Tels
* bump version
+
2007-06-30 v1.87 Tels
* fix undef base in blog()
* support config('lib') as shortcut for config()->{lib}
@@ -957,33 +1147,44 @@ Math::BigInt:
* add bpi(), bcos(), bsin(), batan(), batan2() methods
* add bmuladd()
* streamline the is_xxx() and copy() methods
+
2007-09-22 v1.88 Tels
* fix wide ints on Perl v5.8.0 (Thanx zefram!)
* minimum required is Perl v5.6 (tested by zefram)
* _find_round_parameters(), _scale_a() and _scale_p(): trunc A/P to integers
* fix from_oct(), from_bin() and from_hex()
+
2008-04-20 v1.89 Tels
* fix #35238: batan2() handles inf/+inf wrong
+
2010-09-03 v1.90 rafl
* fix bnok() for k==0 and k==n-1
+
2010-09-10 v1.91 rafl
* fix various documentation bugs
+
2010-09-10 v1.92 rafl
* re-upload v1.91 with a fixed SIGNATURE
+
2010-09-13 v1.93 rafl
* Depend on perl >= 5.6.2
* Remove obsolete core test directory boilerplate
* Convert from Test to Test::More
+
2010-09-13 v1.94 rafl DEVELOPMENT RELEASE
* Attempt to fix Math::BigInt::Lite failures
+
2010-09-14 v1.95 rafl
* Re-upload v1.94 as a stable release
+
2010-09-28 v1.96 rafl
* Various documentation fixes provided by gregor herrmann
+
2010-11-07 v1.97 rafl
* Reorder the list return of Math::BigInt::Calc::_base_len() (Nicholas Clark)
This change requires an update of Math::BigInt::FastCalc to version 0.24.
* Fix segfault when upgrading irrational numbers (Father Chrysostomos)
+
2010-11-08 v1.98 rafl
* Fix from_bin() documentation error (Peter John Acklam) (Closes: RT#61845).
* Make as_int($inf) return inf, not NaN (Peter John Acklam) (Closes RT#62101).
@@ -991,6 +1192,7 @@ Math::BigInt:
(Closes RT#62643).
* Make digit($n) return 0 for "out of range"-digits (Peter John Acklam)
(Closes RT#61812).
+
2010-11-15 v1.99 rafl
* Stop as_int/as_number from losing precision (Peter John Acklam)
(Closes: RT#43694)
@@ -998,6 +1200,7 @@ Math::BigInt:
(Peter John Acklam) (Closes: RT#62918).
* Stop $x -> bmodpow(1, 1) from failing when $x is large (Peter John Acklam)
(Closes: RT#62949).
+
2011-01-29 v1.99_05 pjacklam
* Fix typos (reminder -> remainder etc.) (Peter John Acklam)
* Fix Math::BigInt::Calc::_num returning NaN, not Inf, when it overflowed
@@ -1010,11 +1213,13 @@ Math::BigInt:
(Peter John Acklam) (Closes: RT #61543)
* Clean up whitespace (Nicholas Clark).
* Added file t/00-signature.t for testing SIGNATURE (Peter John Acklam).
+
2011-02-05 v1.991 pjacklam
* Add workaround for library inconsistencies (Math::BigInt::Calc vs.
Math::BigInt::GMP). This makes older versions of Math::BigInt::GMP
work with latest version of Math::BigInt (Peter John Acklam).
* Correct and extend API documentation (Peter John Acklam).
+
2011-02-18 v1.992 pjacklam
* Math::BigInt::Calc->_nok(): Use symmetry property nok(n,k) = nok(n,n-k) to
speed up execution when k is large. Also general code cleanup. (Peter John
@@ -1039,10 +1244,12 @@ Math::BigInt:
Acklam).
* Clean up code and add more code comments (Peter John Acklam).
* Fix typos (Peter John Acklam).
+
2011-02-26 v1.993 pjacklam
* Change default backend library from Math::BigInt::FastCalc to
Math::BigInt::Calc, which is included in the Math-BigInt distro. This
avoids recursive distribution dependency (RT #65976) (Peter John Acklam).
+
2011-09-04 v1.997 pjacklam
* Document actual behaviour of from_xxx() methods. [perl #85334] (Peter John
Acklam)
@@ -1060,6 +1267,11 @@ Math::BigInt:
generated by the end user at configure time after any dynamic dependencies
are known. (Peter John Acklam)
+2014-04-03 v1.9993 pjacklam
+ * Synchronise with blead perl. For a list of recent changes, see
+ http://perl5.git.perl.org/perl.git/history/HEAD:/dist/Math-BigInt
+ * Removed examples/hailstone.pl which required the obsolete Math::Big
+
Please send us test-reports, your experiences with this and your ideas - we love
to hear about our work!
@@ -18,14 +18,14 @@ package Math::BigInt;
my $class = "Math::BigInt";
use 5.006002;
-$VERSION = '1.997';
+$VERSION = '1.9993';
@ISA = qw(Exporter);
-@EXPORT_OK = qw(objectify bgcd blcm);
+@EXPORT_OK = qw(objectify bgcd blcm);
# _trap_inf and _trap_nan are internal and should never be accessed from the
# outside
-use vars qw/$round_mode $accuracy $precision $div_scale $rnd_mode
+use vars qw/$round_mode $accuracy $precision $div_scale $rnd_mode
$upgrade $downgrade $_trap_nan $_trap_inf/;
use strict;
@@ -40,6 +40,8 @@ use strict;
# Thus inheritance of overload operators becomes possible and transparent for
# our subclasses without the need to repeat the entire overload section there.
+# We register ops that are not registerable yet, so suppress warnings
+{ no warnings;
use overload
'=' => sub { $_[0]->copy(); },
@@ -63,39 +65,39 @@ use overload
'..' => \&_pointpoint,
'<=>' => sub { my $rc = $_[2] ?
- ref($_[0])->bcmp($_[1],$_[0]) :
- $_[0]->bcmp($_[1]);
+ ref($_[0])->bcmp($_[1],$_[0]) :
+ $_[0]->bcmp($_[1]);
$rc = 1 unless defined $rc;
$rc <=> 0;
},
# we need '>=' to get things like "1 >= NaN" right:
'>=' => sub { my $rc = $_[2] ?
- ref($_[0])->bcmp($_[1],$_[0]) :
+ ref($_[0])->bcmp($_[1],$_[0]) :
$_[0]->bcmp($_[1]);
# if there was a NaN involved, return false
return '' unless defined $rc;
$rc >= 0;
},
'cmp' => sub {
- $_[2] ?
+ $_[2] ?
"$_[1]" cmp $_[0]->bstr() :
$_[0]->bstr() cmp "$_[1]" },
-'cos' => sub { $_[0]->copy->bcos(); },
-'sin' => sub { $_[0]->copy->bsin(); },
+'cos' => sub { $_[0]->copy->bcos(); },
+'sin' => sub { $_[0]->copy->bsin(); },
'atan2' => sub { $_[2] ?
ref($_[0])->new($_[1])->batan2($_[0]) :
$_[0]->copy()->batan2($_[1]) },
# are not yet overloadable
-#'hex' => sub { print "hex"; $_[0]; },
-#'oct' => sub { print "oct"; $_[0]; },
+#'hex' => sub { print "hex"; $_[0]; },
+#'oct' => sub { print "oct"; $_[0]; },
# log(N) is log(N, e), where e is Euler's number
-'log' => sub { $_[0]->copy()->blog($_[1], undef); },
-'exp' => sub { $_[0]->copy()->bexp($_[1]); },
-'int' => sub { $_[0]->copy(); },
-'neg' => sub { $_[0]->copy()->bneg(); },
+'log' => sub { $_[0]->copy()->blog($_[1], undef); },
+'exp' => sub { $_[0]->copy()->bexp($_[1]); },
+'int' => sub { $_[0]->copy(); },
+'neg' => sub { $_[0]->copy()->bneg(); },
'abs' => sub { $_[0]->copy()->babs(); },
'sqrt' => sub { $_[0]->copy()->bsqrt(); },
'~' => sub { $_[0]->copy()->bnot(); },
@@ -107,30 +109,30 @@ use overload
'+' => sub { $_[0]->copy()->badd($_[1]); },
'*' => sub { $_[0]->copy()->bmul($_[1]); },
-'/' => sub {
+'/' => sub {
$_[2] ? ref($_[0])->new($_[1])->bdiv($_[0]) : $_[0]->copy->bdiv($_[1]);
- },
-'%' => sub {
+ },
+'%' => sub {
$_[2] ? ref($_[0])->new($_[1])->bmod($_[0]) : $_[0]->copy->bmod($_[1]);
- },
-'**' => sub {
+ },
+'**' => sub {
$_[2] ? ref($_[0])->new($_[1])->bpow($_[0]) : $_[0]->copy->bpow($_[1]);
- },
-'<<' => sub {
+ },
+'<<' => sub {
$_[2] ? ref($_[0])->new($_[1])->blsft($_[0]) : $_[0]->copy->blsft($_[1]);
- },
-'>>' => sub {
+ },
+'>>' => sub {
$_[2] ? ref($_[0])->new($_[1])->brsft($_[0]) : $_[0]->copy->brsft($_[1]);
- },
-'&' => sub {
+ },
+'&' => sub {
$_[2] ? ref($_[0])->new($_[1])->band($_[0]) : $_[0]->copy->band($_[1]);
- },
-'|' => sub {
+ },
+'|' => sub {
$_[2] ? ref($_[0])->new($_[1])->bior($_[0]) : $_[0]->copy->bior($_[1]);
- },
-'^' => sub {
+ },
+'^' => sub {
$_[2] ? ref($_[0])->new($_[1])->bxor($_[0]) : $_[0]->copy->bxor($_[1]);
- },
+ },
# can modify arg of ++ and --, so avoid a copy() for speed, but don't
# use $_[0]->bone(), it would modify $_[0] to be 1!
@@ -147,10 +149,11 @@ use overload
},
# the original qw() does not work with the TIESCALAR below, why?
-# Order of arguments unsignificant
+# Order of arguments insignificant
'""' => sub { $_[0]->bstr(); },
'0+' => sub { $_[0]->numify(); }
;
+} # no warnings scope
##############################################################################
# global constants, flags and accessory
@@ -190,9 +193,9 @@ sub FETCH { return $round_mode; }
sub STORE { $rnd_mode = $_[0]->round_mode($_[1]); }
BEGIN
- {
+ {
# tie to enable $rnd_mode to work transparently
- tie $rnd_mode, 'Math::BigInt';
+ tie $rnd_mode, 'Math::BigInt';
# set up some handy alias names
*as_int = \&as_number;
@@ -200,7 +203,7 @@ BEGIN
*is_neg = \&is_negative;
}
-##############################################################################
+##############################################################################
sub round_mode
{
@@ -437,7 +440,7 @@ sub config
}
sub _scale_a
- {
+ {
# select accuracy parameter based on precedence,
# used by bround() and bfround(), may return undef for scale (means no op)
my ($x,$scale,$mode) = @_;
@@ -460,11 +463,11 @@ sub _scale_a
}
sub _scale_p
- {
+ {
# select precision parameter based on precedence,
# used by bround() and bfround(), may return undef for scale (means no op)
my ($x,$scale,$mode) = @_;
-
+
$scale = $x->{_p} unless defined $scale;
no strict 'refs';
@@ -491,7 +494,7 @@ sub copy
if (@_ > 1)
{
my $self = bless {
- sign => $_[1]->{sign},
+ sign => $_[1]->{sign},
value => $CALC->_copy($_[1]->{value}),
}, $_[0] if @_ > 1;
@@ -501,7 +504,7 @@ sub copy
}
my $self = bless {
- sign => $_[0]->{sign},
+ sign => $_[0]->{sign},
value => $CALC->_copy($_[0]->{value}),
}, ref($_[0]);
@@ -510,9 +513,9 @@ sub copy
$self;
}
-sub new
+sub new
{
- # create a new BigInt object from a string or another BigInt object.
+ # create a new BigInt object from a string or another BigInt object.
# see hash keys documented at top
# the argument could be an object, so avoid ||, && etc on it, this would
@@ -520,14 +523,14 @@ sub new
# ref() and defined.
my ($class,$wanted,$a,$p,$r) = @_;
-
+
# avoid numify-calls by not using || on $wanted!
return $class->bzero($a,$p) if !defined $wanted; # default to 0
return $class->copy($wanted,$a,$p,$r)
if ref($wanted) && $wanted->isa($class); # MBI or subclass
$class->import() if $IMPORT == 0; # make require work
-
+
my $self = bless {}, $class;
# shortcut for "normal" numbers
@@ -546,9 +549,9 @@ sub new
$self->{value} = $CALC->_new($wanted);
}
no strict 'refs';
- if ( (defined $a) || (defined $p)
+ if ( (defined $a) || (defined $p)
|| (defined ${"${class}::precision"})
- || (defined ${"${class}::accuracy"})
+ || (defined ${"${class}::accuracy"})
)
{
$self->round($a,$p,$r) unless (@_ == 4 && !defined $a && !defined $p);
@@ -716,14 +719,14 @@ sub bzero
# create a bigint '+0', if given a BigInt, set it to 0
my $self = shift;
$self = __PACKAGE__ if !defined $self;
-
+
if (!ref($self))
{
my $c = $self; $self = {}; bless $self, $c;
}
$self->import() if $IMPORT == 0; # make require work
return if $self->modify('bzero');
-
+
if ($self->can('_bzero'))
{
# use subclass to initialize
@@ -806,7 +809,7 @@ sub bsstr
# (ref to BFLOAT or num_str ) return num_str
# Convert number from internal format to scientific string format.
# internal format is always normalized (no leading zeros, "-0E0" => "+0E0")
- my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
+ my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
if ($x->{sign} !~ /^[+-]$/)
{
@@ -816,13 +819,13 @@ sub bsstr
my ($m,$e) = $x->parts();
#$m->bstr() . 'e+' . $e->bstr(); # e can only be positive in BigInt
# 'e+' because E can only be positive in BigInt
- $m->bstr() . 'e+' . $CALC->_str($e->{value});
+ $m->bstr() . 'e+' . $CALC->_str($e->{value});
}
-sub bstr
+sub bstr
{
# make a string from bigint object
- my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
+ my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
if ($x->{sign} !~ /^[+-]$/)
{
@@ -833,7 +836,7 @@ sub bstr
$es.$CALC->_str($x->{value});
}
-sub numify
+sub numify
{
# Make a "normal" scalar from a BigInt object
my $x = shift; $x = $class->new($x) unless ref $x;
@@ -850,8 +853,8 @@ sub numify
sub sign
{
# return the sign of the number: +/-/-inf/+inf/NaN
- my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
-
+ my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
+
$x->{sign};
}
@@ -865,10 +868,10 @@ sub _find_round_parameters
# This procedure finds the round parameters, but it is for speed reasons
# duplicated in round. Otherwise, it is tested by the testsuite and used
# by fdiv().
-
+
# returns ($self) or ($self,$a,$p,$r) - sets $self to NaN of both A and P
# were requested/defined (locally or globally or both)
-
+
my ($self,$a,$p,$r,@args) = @_;
# $a accuracy, if given by caller
# $p precision, if given by caller
@@ -907,8 +910,8 @@ sub _find_round_parameters
# A == 0 is useless, so undef it to signal no rounding
$a = undef if defined $a && $a == 0;
-
- # no rounding today?
+
+ # no rounding today?
return ($self) unless defined $a || defined $p; # early out
# set A and set P is an fatal error
@@ -929,7 +932,7 @@ sub _find_round_parameters
sub round
{
# Round $self according to given parameters, or given second argument's
- # parameters or global defaults
+ # parameters or global defaults
# for speed reasons, _find_round_parameters is embedded here:
@@ -964,11 +967,11 @@ sub round
# if still none defined, use globals (#2)
$a = ${"$c\::accuracy"} unless defined $a;
$p = ${"$c\::precision"} unless defined $p;
-
+
# A == 0 is useless, so undef it to signal no rounding
$a = undef if defined $a && $a == 0;
-
- # no rounding today?
+
+ # no rounding today?
return $self unless defined $a || defined $p; # early out
# set A and set P is an fatal error
@@ -994,14 +997,14 @@ sub round
}
sub bnorm
- {
+ {
# (numstr or BINT) return BINT
# Normalize number -- no-op here
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
$x;
}
-sub babs
+sub babs
{
# (BINT or num_str) return BINT
# make number absolute, or return absolute BINT from string
@@ -1025,28 +1028,28 @@ sub bsgn {
return $self; # zero or NaN
}
-sub bneg
- {
+sub bneg
+ {
# (BINT or num_str) return BINT
# negate number or make a negated number from string
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
-
+
return $x if $x->modify('bneg');
- # for +0 dont negate (to have always normalized +0). Does nothing for 'NaN'
+ # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN'
$x->{sign} =~ tr/+-/-+/ unless ($x->{sign} eq '+' && $CALC->_is_zero($x->{value}));
$x;
}
-sub bcmp
+sub bcmp
{
# Compares 2 values. Returns one of undef, <0, =0, >0. (suitable for sort)
# (BINT or num_str, BINT or num_str) return cond_code
-
+
# set up parameters
my ($self,$x,$y) = (ref($_[0]),@_);
- # objectify is costly, so avoid it
+ # objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
{
($self,$x,$y) = objectify(2,@_);
@@ -1067,31 +1070,31 @@ sub bcmp
}
# check sign for speed first
return 1 if $x->{sign} eq '+' && $y->{sign} eq '-'; # does also 0 <=> -y
- return -1 if $x->{sign} eq '-' && $y->{sign} eq '+'; # does also -x <=> 0
+ return -1 if $x->{sign} eq '-' && $y->{sign} eq '+'; # does also -x <=> 0
# have same sign, so compare absolute values. Don't make tests for zero here
- # because it's actually slower than testin in Calc (especially w/ Pari et al)
+ # because it's actually slower than testing in Calc (especially w/ Pari et al)
# post-normalized compare for internal use (honors signs)
- if ($x->{sign} eq '+')
+ if ($x->{sign} eq '+')
{
# $x and $y both > 0
return $CALC->_acmp($x->{value},$y->{value});
}
# $x && $y both < 0
- $CALC->_acmp($y->{value},$x->{value}); # swaped acmp (lib returns 0,1,-1)
+ $CALC->_acmp($y->{value},$x->{value}); # swapped acmp (lib returns 0,1,-1)
}
-sub bacmp
+sub bacmp
{
- # Compares 2 values, ignoring their signs.
+ # Compares 2 values, ignoring their signs.
# Returns one of undef, <0, =0, >0. (suitable for sort)
# (BINT, BINT) return cond_code
-
+
# set up parameters
my ($self,$x,$y) = (ref($_[0]),@_);
- # objectify is costly, so avoid it
+ # objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
{
($self,$x,$y) = objectify(2,@_);
@@ -1111,14 +1114,14 @@ sub bacmp
$CALC->_acmp($x->{value},$y->{value}); # lib does only 0,1,-1
}
-sub badd
+sub badd
{
# add second arg (BINT or string) to first (BINT) (modifies first)
# return result as BINT
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
- # objectify is costly, so avoid it
+ # objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
{
($self,$x,$y,@r) = objectify(2,@_);
@@ -1146,21 +1149,21 @@ sub badd
$x->{sign} = $y->{sign}, return $x if $y->{sign} =~ /^[+-]inf$/;
return $x;
}
-
+
my ($sx, $sy) = ( $x->{sign}, $y->{sign} ); # get signs
- if ($sx eq $sy)
+ if ($sx eq $sy)
{
$x->{value} = $CALC->_add($x->{value},$y->{value}); # same sign, abs add
}
- else
+ else
{
my $a = $CALC->_acmp ($y->{value},$x->{value}); # absolute compare
- if ($a > 0)
+ if ($a > 0)
{
$x->{value} = $CALC->_sub($y->{value},$x->{value},1); # abs sub w/ swap
$x->{sign} = $sy;
- }
+ }
elsif ($a == 0)
{
# speedup, if equal, set result to 0
@@ -1175,11 +1178,11 @@ sub badd
$x->round(@r);
}
-sub bsub
+sub bsub
{
# (BINT or num_str, BINT or num_str) return BINT
# subtract second arg from first, modify first
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
@@ -1238,12 +1241,12 @@ sub bdec
# decrement arg by one
my ($self,$x,@r) = ref($_[0]) ? (ref($_[0]),@_) : objectify(1,@_);
return $x if $x->modify('bdec');
-
+
if ($x->{sign} eq '-')
{
# x already < 0
$x->{value} = $CALC->_inc($x->{value});
- }
+ }
else
{
return $x->badd($self->bone('-'),@r) unless $x->{sign} eq '+'; # inf or NaN
@@ -1283,7 +1286,7 @@ sub blog
return $x->bnan()
if $x->{sign} ne '+' || (defined $base && $base->{sign} ne '+');
- return $upgrade->blog($upgrade->new($x),$base,@r) if
+ return $upgrade->blog($upgrade->new($x),$base,@r) if
defined $upgrade;
# fix for bug #24969:
@@ -1297,7 +1300,7 @@ sub blog
$x->{sign} = $u->{sign};
return $x;
}
-
+
my ($rc,$exact) = $CALC->_log_int($x->{value},$base->{value});
return $x->bnan() unless defined $rc; # not possible to take log?
$x->{value} = $rc;
@@ -1402,16 +1405,16 @@ sub blcm
$x = $class->new($y);
}
my $self = ref($x);
- while (@_)
+ while (@_)
{
my $y = shift; $y = $self->new($y) if !ref ($y);
$x = __lcm($x,$y);
- }
+ }
$x;
}
-sub bgcd
- {
+sub bgcd
+ {
# (BINT or num_str, BINT or num_str) return BINT
# does not modify arguments, but returns new object
# GCD -- Euclid's algorithm, variant C (Knuth Vol 3, pg 341 ff)
@@ -1432,13 +1435,13 @@ sub bgcd
$x;
}
-sub bnot
+sub bnot
{
# (num_str or BINT) return BINT
# represent ~x as twos-complement number
# we don't need $self, so undef instead of ref($_[0]) make it slightly faster
my ($self,$x,$a,$p,$r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
-
+
return $x if $x->modify('bnot');
$x->binc()->bneg(); # binc already does round
}
@@ -1451,7 +1454,7 @@ sub is_zero
{
# return true if arg (BINT or num_str) is zero (array '+', '0')
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
-
+
return 0 if $x->{sign} !~ /^\+$/; # -, NaN & +-inf aren't
$CALC->_is_zero($x->{value});
}
@@ -1482,9 +1485,9 @@ sub is_one
{
# return true if arg (BINT or num_str) is +1, or -1 if sign is given
my ($self,$x,$sign) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
-
+
$sign = '+' if !defined $sign || $sign ne '-';
-
+
return 0 if $x->{sign} ne $sign; # -1 != +1, NaN, +-inf aren't either
$CALC->_is_one($x->{value});
}
@@ -1522,7 +1525,7 @@ sub is_negative
{
# return true when arg (BINT or num_str) is negative (< 0)
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
-
+
$x->{sign} =~ /^-/ ? 1 : 0; # -inf is negative, but NaN is not
}
@@ -1531,14 +1534,14 @@ sub is_int
# return true when arg (BINT or num_str) is an integer
# always true for BigInt, but different for BigFloats
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
-
+
$x->{sign} =~ /^[+-]$/ ? 1 : 0; # inf/-inf/NaN aren't
}
###############################################################################
-sub bmul
- {
+sub bmul
+ {
# multiply the first number by the second number
# (BINT or num_str, BINT or num_str) return BINT
@@ -1561,14 +1564,14 @@ sub bmul
# result will always be +-inf:
# +inf * +/+inf => +inf, -inf * -/-inf => +inf
# +inf * -/-inf => -inf, -inf * +/+inf => -inf
- return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/);
- return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/);
+ return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/);
+ return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/);
return $x->binf('-');
}
return $upgrade->bmul($x,$upgrade->new($y),@r)
if defined $upgrade && !$y->isa($self);
-
+
$r[3] = $y; # no push here
$x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; # +1 * +1 or -1 * -1 => +
@@ -1580,7 +1583,7 @@ sub bmul
}
sub bmuladd
- {
+ {
# multiply two numbers and then add the third to the result
# (BINT or num_str, BINT or num_str, BINT or num_str) return BINT
@@ -1600,8 +1603,8 @@ sub bmuladd
# result will always be +-inf:
# +inf * +/+inf => +inf, -inf * -/-inf => +inf
# +inf * -/-inf => -inf, -inf * +/+inf => -inf
- return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/);
- return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/);
+ return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/);
+ return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/);
return $x->binf('-');
}
# inf handling x*y and z
@@ -1613,7 +1616,7 @@ sub bmuladd
return $upgrade->bmuladd($x,$upgrade->new($y),$upgrade->new($z),@r)
if defined $upgrade && (!$y->isa($self) || !$z->isa($self) || !$x->isa($self));
-
+
# TODO: what if $y and $z have A or P set?
$r[3] = $z; # no push here
@@ -1624,18 +1627,18 @@ sub bmuladd
my ($sx, $sz) = ( $x->{sign}, $z->{sign} ); # get signs
- if ($sx eq $sz)
+ if ($sx eq $sz)
{
$x->{value} = $CALC->_add($x->{value},$z->{value}); # same sign, abs add
}
- else
+ else
{
my $a = $CALC->_acmp ($z->{value},$x->{value}); # absolute compare
- if ($a > 0)
+ if ($a > 0)
{
$x->{value} = $CALC->_sub($z->{value},$x->{value},1); # abs sub w/ swap
$x->{sign} = $sz;
- }
+ }
elsif ($a == 0)
{
# speedup, if equal, set result to 0
@@ -1659,7 +1662,7 @@ sub _div_inf
return wantarray ? ($x->bnan(),$self->bnan()) : $x->bnan()
if (($x->is_nan() || $y->is_nan()) ||
($x->is_zero() && $y->is_zero()));
-
+
# +-inf / +-inf == NaN, remainder also NaN
if (($x->{sign} =~ /^[+-]inf$/) && ($y->{sign} =~ /^[+-]inf$/))
{
@@ -1671,9 +1674,9 @@ sub _div_inf
my $t = $x->copy(); # bzero clobbers up $x
return wantarray ? ($x->bzero(),$t) : $x->bzero()
}
-
+
# 5 / 0 => +inf, -6 / 0 => -inf
- # +inf / 0 = inf, inf, and -inf / 0 => -inf, -inf
+ # +inf / 0 = inf, inf, and -inf / 0 => -inf, -inf
# exception: -8 / 0 has remainder -8, not 8
# exception: -inf / 0 has remainder -inf, not inf
if ($y->is_zero())
@@ -1687,7 +1690,7 @@ sub _div_inf
($x->binf($x->{sign}),$t) : $x->binf($x->{sign})
}
}
-
+
# last case: +-inf / ordinary number
my $sign = '+inf';
$sign = '-inf' if substr($x->{sign},0,1) ne $y->{sign};
@@ -1695,18 +1698,18 @@ sub _div_inf
return wantarray ? ($x,$self->bzero()) : $x;
}
-sub bdiv
+sub bdiv
{
- # (dividend: BINT or num_str, divisor: BINT or num_str) return
+ # (dividend: BINT or num_str, divisor: BINT or num_str) return
# (BINT,BINT) (quo,rem) or BINT (only rem)
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
- # objectify is costly, so avoid it
+ # objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
{
($self,$x,$y,@r) = objectify(2,@_);
- }
+ }
return $x if $x->modify('bdiv');
@@ -1715,16 +1718,16 @@ sub bdiv
return $upgrade->bdiv($upgrade->new($x),$upgrade->new($y),@r)
if defined $upgrade;
-
+
$r[3] = $y; # no push!
# calc new sign and in case $y == +/- 1, return $x
my $xsign = $x->{sign}; # keep
- $x->{sign} = ($x->{sign} ne $y->{sign} ? '-' : '+');
+ $x->{sign} = ($x->{sign} ne $y->{sign} ? '-' : '+');
if (wantarray)
{
- my $rem = $self->bzero();
+ my $rem = $self->bzero();
($x->{value},$rem->{value}) = $CALC->_div($x->{value},$y->{value});
$x->{sign} = '+' if $CALC->_is_zero($x->{value});
$rem->{_a} = $x->{_a};
@@ -1737,7 +1740,7 @@ sub bdiv
}
else
{
- $rem->{sign} = '+'; # dont leave -0
+ $rem->{sign} = '+'; # do not leave -0
}
$rem->round(@r);
return ($x,$rem);
@@ -1752,11 +1755,11 @@ sub bdiv
###############################################################################
# modulus functions
-sub bmod
+sub bmod
{
# modulus (or remainder)
# (BINT or num_str, BINT or num_str) return BINT
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -1785,7 +1788,7 @@ sub bmod
}
else
{
- $x->{sign} = '+'; # dont leave -0
+ $x->{sign} = '+'; # do not leave -0
}
$x->round(@r);
}
@@ -1972,8 +1975,8 @@ sub bfac
$x->{value} = $CALC->_fac($x->{value});
$x->round(@r);
}
-
-sub bpow
+
+sub bpow
{
# (BINT or num_str, BINT or num_str) return BINT
# compute power of two numbers -- stolen from Knuth Vol 2 pg 233
@@ -2018,7 +2021,7 @@ sub bpow
# 1 ** +inf => 1
return $x if $x->is_one();
-
+
# 0 ** inf => 0
return $x if $x->is_zero() && $y->{sign} =~ /^[+]/;
@@ -2048,10 +2051,10 @@ sub bpow
# cases 0 ** Y, X ** 0, X ** 1, 1 ** Y are handled by Calc or Emu
my $new_sign = '+';
- $new_sign = $y->is_odd() ? '-' : '+' if ($x->{sign} ne '+');
+ $new_sign = $y->is_odd() ? '-' : '+' if ($x->{sign} ne '+');
- # 0 ** -7 => ( 1 / (0 ** 7)) => 1 / 0 => +inf
- return $x->binf()
+ # 0 ** -7 => ( 1 / (0 ** 7)) => 1 / 0 => +inf
+ return $x->binf()
if $y->{sign} eq '-' && $x->{sign} eq '+' && $CALC->_is_zero($x->{value});
# 1 ** -y => 1 / (1 ** |y|)
# so do test for negative $y after above's clause
@@ -2063,11 +2066,11 @@ sub bpow
$x->round(@r);
}
-sub blsft
+sub blsft
{
# (BINT or num_str, BINT or num_str) return BINT
# compute x << y, base n, y >= 0
-
+
# set up parameters
my ($self,$x,$y,$n,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -2086,11 +2089,11 @@ sub blsft
$x->round(@r);
}
-sub brsft
+sub brsft
{
# (BINT or num_str, BINT or num_str) return BINT
# compute x >> y, base n, y >= 0
-
+
# set up parameters
my ($self,$x,$y,$n,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -2124,10 +2127,10 @@ sub brsft
if ($y >= CORE::length($bin))
{
$bin = '0'; # shifting to far right creates -1
- # 0, because later increment makes
+ # 0, because later increment makes
# that 1, attached '-' makes it '-1'
# because -1 >> x == -1 !
- }
+ }
else
{
$bin =~ s/.{$y}$//; # cut off at the right side
@@ -2147,11 +2150,11 @@ sub brsft
$x->round(@r);
}
-sub band
+sub band
{
#(BINT or num_str, BINT or num_str) return BINT
# compute x & y
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -2159,7 +2162,7 @@ sub band
{
($self,$x,$y,@r) = objectify(2,@_);
}
-
+
return $x if $x->modify('band');
$r[3] = $y; # no push!
@@ -2168,28 +2171,28 @@ sub band
my $sx = $x->{sign} eq '+' ? 1 : -1;
my $sy = $y->{sign} eq '+' ? 1 : -1;
-
+
if ($sx == 1 && $sy == 1)
{
$x->{value} = $CALC->_and($x->{value},$y->{value});
return $x->round(@r);
}
-
+
if ($CAN{signed_and})
{
$x->{value} = $CALC->_signed_and($x->{value},$y->{value},$sx,$sy);
return $x->round(@r);
}
-
+
require $EMU_LIB;
__emu_band($self,$x,$y,$sx,$sy,@r);
}
-sub bior
+sub bior
{
#(BINT or num_str, BINT or num_str) return BINT
# compute x | y
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -2207,7 +2210,7 @@ sub bior
my $sy = $y->{sign} eq '+' ? 1 : -1;
# the sign of X follows the sign of X, e.g. sign of Y irrelevant for bior()
-
+
# don't use lib for negative values
if ($sx == 1 && $sy == 1)
{
@@ -2226,11 +2229,11 @@ sub bior
__emu_bior($self,$x,$y,$sx,$sy,@r);
}
-sub bxor
+sub bxor
{
#(BINT or num_str, BINT or num_str) return BINT
# compute x ^ y
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -2243,7 +2246,7 @@ sub bxor
$r[3] = $y; # no push!
return $x->bnan() if ($x->{sign} !~ /^[+-]$/ || $y->{sign} !~ /^[+-]$/);
-
+
my $sx = $x->{sign} eq '+' ? 1 : -1;
my $sy = $y->{sign} eq '+' ? 1 : -1;
@@ -2253,7 +2256,7 @@ sub bxor
$x->{value} = $CALC->_xor($x->{value},$y->{value});
return $x->round(@r);
}
-
+
# if lib can do negative values, let it handle this
if ($CAN{signed_xor})
{
@@ -2269,7 +2272,7 @@ sub length
{
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
- my $e = $CALC->_len($x->{value});
+ my $e = $CALC->_len($x->{value});
wantarray ? ($e,0) : $e;
}
@@ -2312,7 +2315,7 @@ sub bsqrt
sub broot
{
# calculate $y'th root of $x
-
+
# set up parameters
my ($self,$x,$y,@r) = (ref($_[0]),@_);
@@ -2343,7 +2346,7 @@ sub exponent
{
# return a copy of the exponent (here always 0, NaN or 1 for $m == 0)
my ($self,$x) = ref($_[0]) ? (ref($_[0]),$_[0]) : objectify(1,@_);
-
+
if ($x->{sign} !~ /^[+-]$/)
{
my $s = $x->{sign}; $s =~ s/^[+-]//; # NaN, -inf,+inf => NaN or inf
@@ -2380,7 +2383,7 @@ sub parts
($x->mantissa(),$x->exponent());
}
-
+
##############################################################################
# rounding functions
@@ -2406,7 +2409,7 @@ sub _scan_for_nonzero
{
# internal, used by bround() to scan for non-zeros after a '5'
my ($x,$pad,$xs,$len) = @_;
-
+
return 0 if $len == 1; # "5" is trailed by invisible zeros
my $follow = $pad - 1;
return 0 if $follow > $len || $follow < 1;
@@ -2434,7 +2437,7 @@ sub bround
my $x = shift; $x = $class->new($x) unless ref $x;
my ($scale,$mode) = $x->_scale_a(@_);
return $x if !defined $scale || $x->modify('bround'); # no-op
-
+
if ($x->is_zero() || $scale == 0)
{
$x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; # 3 > 2
@@ -2453,9 +2456,9 @@ sub bround
if (($scale < 0 && $scale < -$len-1) || ($scale >= $len))
{
$x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; # 3 > 2
- return $x;
+ return $x;
}
-
+
# count of 0's to pad, from left (+) or right (-): 9 - +6 => 3, or |-6| => 6
my ($pad,$digit_round,$digit_after);
$pad = $len - $scale;
@@ -2489,7 +2492,7 @@ sub bround
($mode eq 'zero') # round down if zero, sign adjusted below
);
my $put_back = 0; # not yet modified
-
+
if (($pad > 0) && ($pad <= $len))
{
substr($xs,-$pad,$pad) = '0' x $pad; # replace with '00...'
@@ -2503,7 +2506,7 @@ sub bround
if ($round_up) # what gave test above?
{
$put_back = 1; # need to put back
- $pad = $len, $xs = '0' x $pad if $scale < 0; # tlr: whack 0.51=>1.0
+ $pad = $len, $xs = '0' x $pad if $scale < 0; # tlr: whack 0.51=>1.0
# we modify directly the string variant instead of creating a number and
# adding it, since that is faster (we already have the string)
@@ -2530,7 +2533,7 @@ sub bround
sub bfloor
{
- # return integer less or equal then number; no-op since it's already integer
+ # round towards minus infinity; no-op since it's already integer
my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
$x->round(@r);
@@ -2538,12 +2541,19 @@ sub bfloor
sub bceil
{
- # return integer greater or equal then number; no-op since it's already int
+ # round towards plus infinity; no-op since it's already int
my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
$x->round(@r);
}
+sub bint {
+ # round towards zero; no-op since it's already integer
+ my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
+
+ $x->round(@r);
+}
+
sub as_number
{
# An object might be asked to return itself as bigint on certain overloaded
@@ -2726,14 +2736,14 @@ sub _register_callback
my ($class,$callback) = @_;
if (ref($callback) ne 'CODE')
- {
+ {
require Carp;
Carp::croak ("$callback is not a coderef");
}
$CALLBACKS{$class} = $callback;
}
-sub import
+sub import
{
my $self = shift;
@@ -2745,7 +2755,7 @@ sub import
if ($_[$i] eq ':constant')
{
# this causes overlord er load to step in
- overload::constant
+ overload::constant
integer => sub { $self->new(shift) },
binary => sub { $self->new(shift) };
}
@@ -2773,7 +2783,7 @@ sub import
if (@a > 0)
{
require Exporter;
-
+
$self->SUPER::import(@a); # need it for subclasses
$self->export_to_level(1,$self,@a); # need it for MBF
}
@@ -2837,7 +2847,7 @@ sub import
Carp::carp ("$lib is missing method '_$method'");
$WARN{$lib} = 1; # still warn about the lib
}
- $ok++; last;
+ $ok++; last;
}
}
}
@@ -3067,9 +3077,9 @@ sub _split
$x =~ s/([0-9])_([0-9])/$1$2/g;
$x =~ s/([0-9])_([0-9])/$1$2/g; # do twice for 1_2_3
- # some possible inputs:
- # 2.1234 # 0.12 # 1 # 1E1 # 2.134E1 # 434E-10 # 1.02009E-2
- # .2 # 1_2_3.4_5_6 # 1.4E1_2_3 # 1e3 # +.2 # 0e999
+ # some possible inputs:
+ # 2.1234 # 0.12 # 1 # 1E1 # 2.134E1 # 434E-10 # 1.02009E-2
+ # .2 # 1_2_3.4_5_6 # 1.4E1_2_3 # 1e3 # +.2 # 0e999
my ($m,$e,$last) = split /[Ee]/,$x;
return if defined $last; # last defined => 1e2E3 or others
@@ -3104,12 +3114,12 @@ sub _split
##############################################################################
# internal calculation routines (others are in Math::BigInt::Calc etc)
-sub __lcm
- {
+sub __lcm
+ {
# (BINT or num_str, BINT or num_str) return BINT
# does modify first argument
# LCM
-
+
my ($x,$ty) = @_;
return $x->bnan() if ($x->{sign} eq $nan) || ($ty->{sign} eq $nan);
my $method = ref($x) . '::bgcd';
@@ -3181,9 +3191,9 @@ sub bsin
}
sub batan2
- {
+ {
# calculate arcus tangens of ($y/$x)
-
+
# set up parameters
my ($self,$y,$x,@r) = (ref($_[0]),@_);
# objectify is costly, so avoid it
@@ -3306,7 +3316,7 @@ Math::BigInt - Arbitrary size integer/float math package
my @values = (64,74,18);
my $n = 1; my $sign = '-';
- # Number creation
+ # Number creation
my $x = Math::BigInt->new($str); # defaults to 0
my $y = $x->copy(); # make a true copy
my $nan = Math::BigInt->bnan(); # create a NotANumber
@@ -3372,33 +3382,33 @@ Math::BigInt - Arbitrary size integer/float math package
$x->bmuladd($y,$z); # $x = $x * $y + $z
- $x->bmod($y); # modulus (x % y)
- $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod)
- $x->bmodinv($mod); # modular multiplicative inverse
- $x->bpow($y); # power of arguments (x ** y)
- $x->blsft($y); # left shift in base 2
- $x->brsft($y); # right shift in base 2
- # returns (quo,rem) or quo if in sca-
- # lar context
- $x->blsft($y,$n); # left shift by $y places in base $n
- $x->brsft($y,$n); # right shift by $y places in base $n
- # returns (quo,rem) or quo if in sca-
- # lar context
-
- $x->band($y); # bitwise and
- $x->bior($y); # bitwise inclusive or
- $x->bxor($y); # bitwise exclusive or
- $x->bnot(); # bitwise not (two's complement)
-
- $x->bsqrt(); # calculate square-root
- $x->broot($y); # $y'th root of $x (e.g. $y == 3 => cubic root)
- $x->bfac(); # factorial of $x (1*2*3*4*..$x)
-
- $x->bnok($y); # x over y (binomial coefficient n over k)
-
- $x->blog(); # logarithm of $x to base e (Euler's number)
- $x->blog($base); # logarithm of $x to base $base (f.i. 2)
- $x->bexp(); # calculate e ** $x where e is Euler's number
+ $x->bmod($y); # modulus (x % y)
+ $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod)
+ $x->bmodinv($mod); # modular multiplicative inverse
+ $x->bpow($y); # power of arguments (x ** y)
+ $x->blsft($y); # left shift in base 2
+ $x->brsft($y); # right shift in base 2
+ # returns (quo,rem) or quo if in sca-
+ # lar context
+ $x->blsft($y,$n); # left shift by $y places in base $n
+ $x->brsft($y,$n); # right shift by $y places in base $n
+ # returns (quo,rem) or quo if in sca-
+ # lar context
+
+ $x->band($y); # bitwise and
+ $x->bior($y); # bitwise inclusive or
+ $x->bxor($y); # bitwise exclusive or
+ $x->bnot(); # bitwise not (two's complement)
+
+ $x->bsqrt(); # calculate square-root
+ $x->broot($y); # $y'th root of $x (e.g. $y == 3 => cubic root)
+ $x->bfac(); # factorial of $x (1*2*3*4*..$x)
+
+ $x->bnok($y); # x over y (binomial coefficient n over k)
+
+ $x->blog(); # logarithm of $x to base e (Euler's number)
+ $x->blog($base); # logarithm of $x to base $base (f.i. 2)
+ $x->bexp(); # calculate e ** $x where e is Euler's number
$x->round($A,$P,$mode); # round to accuracy or precision using
# mode $mode
@@ -3410,8 +3420,9 @@ Math::BigInt - Arbitrary size integer/float math package
# The following do not modify their arguments in BigInt (are no-ops),
# but do so in BigFloat:
- $x->bfloor(); # return integer less or equal than $x
- $x->bceil(); # return integer greater or equal than $x
+ $x->bfloor(); # round towards minus infinity
+ $x->bceil(); # round towards plus infinity
+ $x->bint(); # round towards zero
# The following do not modify their arguments:
@@ -3464,9 +3475,7 @@ declare your big integers as
Operations with overloaded operators preserve the arguments which is
exactly what you expect.
-=over 2
-
-=item Input
+=head2 Input
Input values to these routines may be any string, that looks like a number
and results in an integer, including hexadecimal and binary numbers.
@@ -3500,11 +3509,11 @@ explicit forms to get a zero or NaN:
$zero = Math::BigInt->bzero();
$nan = Math::BigInt->bnan();
-C<bnorm()> on a BigInt object is now effectively a no-op, since the numbers
-are always stored in normalized form. If passed a string, creates a BigInt
+C<bnorm()> on a BigInt object is now effectively a no-op, since the numbers
+are always stored in normalized form. If passed a string, creates a BigInt
object from the input.
-=item Output
+=head2 Output
Output values are BigInt objects (normalized), except for the methods which
return a string (see L</SYNOPSIS>).
@@ -3513,8 +3522,6 @@ Some routines (C<is_odd()>, C<is_even()>, C<is_zero()>, C<is_one()>,
C<is_nan()>, etc.) return true or false, while others (C<bcmp()>, C<bacmp()>)
return either undef (if NaN is involved), <0, 0 or >0 and are suited for sort.
-=back
-
=head1 METHODS
Each of the methods below (except config(), accuracy() and precision())
@@ -3522,44 +3529,46 @@ accepts three additional parameters. These arguments C<$A>, C<$P> and C<$R>
are C<accuracy>, C<precision> and C<round_mode>. Please see the section about
L</ACCURACY and PRECISION> for more information.
-=head2 config()
+=over
- use Data::Dumper;
+=item config()
- print Dumper ( Math::BigInt->config() );
- print Math::BigInt->config()->{lib},"\n";
+ use Data::Dumper;
+
+ print Dumper ( Math::BigInt->config() );
+ print Math::BigInt->config()->{lib},"\n";
Returns a hash containing the configuration, e.g. the version number, lib
loaded etc. The following hash keys are currently filled in with the
appropriate information.
- key Description
- Example
- ============================================================
- lib Name of the low-level math library
- Math::BigInt::Calc
- lib_version Version of low-level math library (see 'lib')
- 0.30
- class The class name of config() you just called
- Math::BigInt
- upgrade To which class math operations might be upgraded
- Math::BigFloat
- downgrade To which class math operations might be downgraded
- undef
- precision Global precision
- undef
- accuracy Global accuracy
- undef
- round_mode Global round mode
- even
- version version number of the class you used
- 1.61
- div_scale Fallback accuracy for div
- 40
- trap_nan If true, traps creation of NaN via croak()
- 1
- trap_inf If true, traps creation of +inf/-inf via croak()
- 1
+ key Description
+ Example
+ ============================================================
+ lib Name of the low-level math library
+ Math::BigInt::Calc
+ lib_version Version of low-level math library (see 'lib')
+ 0.30
+ class The class name of config() you just called
+ Math::BigInt
+ upgrade To which class math operations might be
+ upgraded Math::BigFloat
+ downgrade To which class math operations might be
+ downgraded undef
+ precision Global precision
+ undef
+ accuracy Global accuracy
+ undef
+ round_mode Global round mode
+ even
+ version version number of the class you used
+ 1.61
+ div_scale Fallback accuracy for div
+ 40
+ trap_nan If true, traps creation of NaN via croak()
+ 1
+ trap_inf If true, traps creation of +inf/-inf via croak()
+ 1
The following values can be set by passing C<config()> a reference to a hash:
@@ -3572,7 +3581,7 @@ Example:
{ trap_inf => 1, precision => 5 }
);
-=head2 accuracy()
+=item accuracy()
$x->accuracy(5); # local for $x
CLASS->accuracy(5); # global for all members of CLASS
@@ -3614,7 +3623,8 @@ represents the accuracy that will be in effect for $x:
# ally rounded!
print "$x $y\n"; # '123500 1234567'
print $x->accuracy(),"\n"; # will be 4
- print $y->accuracy(),"\n"; # also 4, since global is 4
+ print $y->accuracy(),"\n"; # also 4, since
+ # global is 4
print Math::BigInt->accuracy(5),"\n"; # set to 5, print 5
print $x->accuracy(),"\n"; # still 4
print $y->accuracy(),"\n"; # 5, since global is 5
@@ -3624,19 +3634,19 @@ globals separated from Math::BigInt, but it is possible to subclass
Math::BigInt and make the globals of the subclass aliases to the ones from
Math::BigInt.
-=head2 precision()
+=item precision()
- $x->precision(-2); # local for $x, round at the second
- # digit right of the dot
- $x->precision(2); # ditto, round at the second digit left
- # of the dot
+ $x->precision(-2); # local for $x, round at the second
+ # digit right of the dot
+ $x->precision(2); # ditto, round at the second digit
+ # left of the dot
- CLASS->precision(5); # Global for all members of CLASS
- # This also applies to new()!
- CLASS->precision(-5); # ditto
+ CLASS->precision(5); # Global for all members of CLASS
+ # This also applies to new()!
+ CLASS->precision(-5); # ditto
- $P = CLASS->precision(); # read out global precision
- $P = $x->precision(); # read out precision that affects $x
+ $P = CLASS->precision(); # read out global precision
+ $P = $x->precision(); # read out precision that affects $x
Note: You probably want to use L</accuracy()> instead. With L</accuracy()> you
set the number of digits each result should have, with L</precision()> you
@@ -3663,7 +3673,7 @@ value represents the prevision that will be in effect for $x:
$y = Math::BigInt->new(1234567); # unrounded
print Math::BigInt->precision(4),"\n"; # set 4, print 4
- $x = Math::BigInt->new(123456); # will be automatically rounded
+ $x = Math::BigInt->new(123456); # will be automatically rounded
print $x; # print "120000"!
Note: Works also for subclasses like L<Math::BigFloat>. Each class has its
@@ -3671,9 +3681,9 @@ own globals separated from Math::BigInt, but it is possible to subclass
Math::BigInt and make the globals of the subclass aliases to the ones from
Math::BigInt.
-=head2 brsft()
+=item brsft()
- $x->brsft($y,$n);
+ $x->brsft($y,$n);
Shifts $x right by $y in base $n. Default is base 2, used are usually 10 and
2, but others work, too.
@@ -3682,23 +3692,23 @@ Right shifting usually amounts to dividing $x by $n ** $y and truncating the
result:
- $x = Math::BigInt->new(10);
- $x->brsft(1); # same as $x >> 1: 5
- $x = Math::BigInt->new(1234);
- $x->brsft(2,10); # result 12
+ $x = Math::BigInt->new(10);
+ $x->brsft(1); # same as $x >> 1: 5
+ $x = Math::BigInt->new(1234);
+ $x->brsft(2,10); # result 12
There is one exception, and that is base 2 with negative $x:
- $x = Math::BigInt->new(-5);
- print $x->brsft(1);
+ $x = Math::BigInt->new(-5);
+ print $x->brsft(1);
This will print -3, not -2 (as it would if you divide -5 by 2 and truncate the
result).
-=head2 new()
+=item new()
- $x = Math::BigInt->new($str,$A,$P,$R);
+ $x = Math::BigInt->new($str,$A,$P,$R);
Creates a new BigInt object from a scalar or another BigInt object. The
input is accepted as decimal, hex (with leading '0x') or binary (with leading
@@ -3706,90 +3716,90 @@ input is accepted as decimal, hex (with leading '0x') or binary (with leading
See L</Input> for more info on accepted input formats.
-=head2 from_oct()
+=item from_oct()
- $x = Math::BigInt->from_oct("0775"); # input is octal
+ $x = Math::BigInt->from_oct("0775"); # input is octal
Interpret the input as an octal string and return the corresponding value. A
"0" (zero) prefix is optional. A single underscore character may be placed
right after the prefix, if present, or between any two digits. If the input is
invalid, a NaN is returned.
-=head2 from_hex()
+=item from_hex()
- $x = Math::BigInt->from_hex("0xcafe"); # input is hexadecimal
+ $x = Math::BigInt->from_hex("0xcafe"); # input is hexadecimal
Interpret input as a hexadecimal string. A "0x" or "x" prefix is optional. A
single underscore character may be placed right after the prefix, if present,
or between any two digits. If the input is invalid, a NaN is returned.
-=head2 from_bin()
+=item from_bin()
- $x = Math::BigInt->from_bin("0b10011"); # input is binary
+ $x = Math::BigInt->from_bin("0b10011"); # input is binary
Interpret the input as a binary string. A "0b" or "b" prefix is optional. A
single underscore character may be placed right after the prefix, if present,
or between any two digits. If the input is invalid, a NaN is returned.
-=head2 bnan()
+=item bnan()
- $x = Math::BigInt->bnan();
+ $x = Math::BigInt->bnan();
Creates a new BigInt object representing NaN (Not A Number).
If used on an object, it will set it to NaN:
- $x->bnan();
+ $x->bnan();
-=head2 bzero()
+=item bzero()
- $x = Math::BigInt->bzero();
+ $x = Math::BigInt->bzero();
Creates a new BigInt object representing zero.
If used on an object, it will set it to zero:
- $x->bzero();
+ $x->bzero();
-=head2 binf()
+=item binf()
- $x = Math::BigInt->binf($sign);
+ $x = Math::BigInt->binf($sign);
Creates a new BigInt object representing infinity. The optional argument is
either '-' or '+', indicating whether you want infinity or minus infinity.
If used on an object, it will set it to infinity:
- $x->binf();
- $x->binf('-');
+ $x->binf();
+ $x->binf('-');
-=head2 bone()
+=item bone()
- $x = Math::BigInt->binf($sign);
+ $x = Math::BigInt->binf($sign);
Creates a new BigInt object representing one. The optional argument is
either '-' or '+', indicating whether you want one or minus one.
If used on an object, it will set it to one:
- $x->bone(); # +1
- $x->bone('-'); # -1
+ $x->bone(); # +1
+ $x->bone('-'); # -1
-=head2 is_one()/is_zero()/is_nan()/is_inf()
+=item is_one()/is_zero()/is_nan()/is_inf()
- $x->is_zero(); # true if arg is +0
- $x->is_nan(); # true if arg is NaN
- $x->is_one(); # true if arg is +1
- $x->is_one('-'); # true if arg is -1
- $x->is_inf(); # true if +inf
- $x->is_inf('-'); # true if -inf (sign is default '+')
+ $x->is_zero(); # true if arg is +0
+ $x->is_nan(); # true if arg is NaN
+ $x->is_one(); # true if arg is +1
+ $x->is_one('-'); # true if arg is -1
+ $x->is_inf(); # true if +inf
+ $x->is_inf('-'); # true if -inf (sign is default '+')
These methods all test the BigInt for being one specific value and return
true or false depending on the input. These are faster than doing something
like:
- if ($x == 0)
+ if ($x == 0)
-=head2 is_pos()/is_neg()/is_positive()/is_negative()
+=item is_pos()/is_neg()/is_positive()/is_negative()
- $x->is_pos(); # true if > 0
- $x->is_neg(); # true if < 0
+ $x->is_pos(); # true if > 0
+ $x->is_neg(); # true if < 0
The methods return true if the argument is positive or negative, respectively.
C<NaN> is neither positive nor negative, while C<+inf> counts as positive, and
@@ -3802,177 +3812,177 @@ C<is_neg()>, respectively. C<is_positive()> and C<is_negative()> were
introduced in v1.36, while C<is_pos()> and C<is_neg()> were only introduced
in v1.68.
-=head2 is_odd()/is_even()/is_int()
+=item is_odd()/is_even()/is_int()
- $x->is_odd(); # true if odd, false for even
- $x->is_even(); # true if even, false for odd
- $x->is_int(); # true if $x is an integer
+ $x->is_odd(); # true if odd, false for even
+ $x->is_even(); # true if even, false for odd
+ $x->is_int(); # true if $x is an integer
The return true when the argument satisfies the condition. C<NaN>, C<+inf>,
C<-inf> are not integers and are neither odd nor even.
In BigInt, all numbers except C<NaN>, C<+inf> and C<-inf> are integers.
-=head2 bcmp()
+=item bcmp()
- $x->bcmp($y);
+ $x->bcmp($y);
Compares $x with $y and takes the sign into account.
Returns -1, 0, 1 or undef.
-=head2 bacmp()
+=item bacmp()
- $x->bacmp($y);
+ $x->bacmp($y);
Compares $x with $y while ignoring their sign. Returns -1, 0, 1 or undef.
-=head2 sign()
+=item sign()
- $x->sign();
+ $x->sign();
Return the sign, of $x, meaning either C<+>, C<->, C<-inf>, C<+inf> or NaN.
If you want $x to have a certain sign, use one of the following methods:
- $x->babs(); # '+'
- $x->babs()->bneg(); # '-'
- $x->bnan(); # 'NaN'
- $x->binf(); # '+inf'
- $x->binf('-'); # '-inf'
+ $x->babs(); # '+'
+ $x->babs()->bneg(); # '-'
+ $x->bnan(); # 'NaN'
+ $x->binf(); # '+inf'
+ $x->binf('-'); # '-inf'
-=head2 digit()
+=item digit()
- $x->digit($n); # return the nth digit, counting from right
+ $x->digit($n); # return the nth digit, counting from right
If C<$n> is negative, returns the digit counting from left.
-=head2 bneg()
+=item bneg()
- $x->bneg();
+ $x->bneg();
Negate the number, e.g. change the sign between '+' and '-', or between '+inf'
and '-inf', respectively. Does nothing for NaN or zero.
-=head2 babs()
+=item babs()
- $x->babs();
+ $x->babs();
Set the number to its absolute value, e.g. change the sign from '-' to '+'
and from '-inf' to '+inf', respectively. Does nothing for NaN or positive
numbers.
-=head2 bsgn()
+=item bsgn()
- $x->bsgn();
+ $x->bsgn();
Signum function. Set the number to -1, 0, or 1, depending on whether the
-number is negative, zero, or positive, respectivly. Does not modify NaNs.
+number is negative, zero, or positive, respectively. Does not modify NaNs.
-=head2 bnorm()
+=item bnorm()
- $x->bnorm(); # normalize (no-op)
+ $x->bnorm(); # normalize (no-op)
-=head2 bnot()
+=item bnot()
- $x->bnot();
+ $x->bnot();
Two's complement (bitwise not). This is equivalent to
- $x->binc()->bneg();
+ $x->binc()->bneg();
but faster.
-=head2 binc()
+=item binc()
- $x->binc(); # increment x by 1
+ $x->binc(); # increment x by 1
-=head2 bdec()
+=item bdec()
- $x->bdec(); # decrement x by 1
+ $x->bdec(); # decrement x by 1
-=head2 badd()
+=item badd()
- $x->badd($y); # addition (add $y to $x)
+ $x->badd($y); # addition (add $y to $x)
-=head2 bsub()
+=item bsub()
- $x->bsub($y); # subtraction (subtract $y from $x)
+ $x->bsub($y); # subtraction (subtract $y from $x)
-=head2 bmul()
+=item bmul()
- $x->bmul($y); # multiplication (multiply $x by $y)
+ $x->bmul($y); # multiplication (multiply $x by $y)
-=head2 bmuladd()
+=item bmuladd()
- $x->bmuladd($y,$z);
+ $x->bmuladd($y,$z);
Multiply $x by $y, and then add $z to the result,
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bdiv()
+=item bdiv()
- $x->bdiv($y); # divide, set $x to quotient
+ $x->bdiv($y); # divide, set $x to quotient
# return (quo,rem) or quo if scalar
-=head2 bmod()
+=item bmod()
- $x->bmod($y); # modulus (x % y)
+ $x->bmod($y); # modulus (x % y)
-=head2 bmodinv()
+=item bmodinv()
- $x->bmodinv($mod); # modular multiplicative inverse
+ $x->bmodinv($mod); # modular multiplicative inverse
Returns the multiplicative inverse of C<$x> modulo C<$mod>. If
- $y = $x -> copy() -> bmodinv($mod)
+ $y = $x -> copy() -> bmodinv($mod)
then C<$y> is the number closest to zero, and with the same sign as C<$mod>,
satisfying
- ($x * $y) % $mod = 1 % $mod
+ ($x * $y) % $mod = 1 % $mod
If C<$x> and C<$y> are non-zero, they must be relative primes, i.e.,
C<bgcd($y, $mod)==1>. 'C<NaN>' is returned when no modular multiplicative
inverse exists.
-=head2 bmodpow()
+=item bmodpow()
- $num->bmodpow($exp,$mod); # modular exponentiation
+ $num->bmodpow($exp,$mod); # modular exponentiation
# ($num**$exp % $mod)
Returns the value of C<$num> taken to the power C<$exp> in the modulus
C<$mod> using binary exponentiation. C<bmodpow> is far superior to
writing
- $num ** $exp % $mod
+ $num ** $exp % $mod
because it is much faster - it reduces internal variables into
the modulus whenever possible, so it operates on smaller numbers.
C<bmodpow> also supports negative exponents.
- bmodpow($num, -1, $mod)
+ bmodpow($num, -1, $mod)
is exactly equivalent to
- bmodinv($num, $mod)
+ bmodinv($num, $mod)
-=head2 bpow()
+=item bpow()
- $x->bpow($y); # power of arguments (x ** y)
+ $x->bpow($y); # power of arguments (x ** y)
-=head2 blog()
+=item blog()
- $x->blog($base, $accuracy); # logarithm of x to the base $base
+ $x->blog($base, $accuracy); # logarithm of x to the base $base
If C<$base> is not defined, Euler's number (e) is used:
- print $x->blog(undef, 100); # log(x) to 100 digits
+ print $x->blog(undef, 100); # log(x) to 100 digits
-=head2 bexp()
+=item bexp()
- $x->bexp($accuracy); # calculate e ** X
+ $x->bexp($accuracy); # calculate e ** X
Calculates the expression C<e ** $x> where C<e> is Euler's number.
@@ -3980,9 +3990,9 @@ This method was added in v1.82 of Math::BigInt (April 2007).
See also L</blog()>.
-=head2 bnok()
+=item bnok()
- $x->bnok($y); # x over y (binomial coefficient n over k)
+ $x->bnok($y); # x over y (binomial coefficient n over k)
Calculates the binomial coefficient n over k, also called the "choose"
function. The result is equivalent to:
@@ -3993,9 +4003,9 @@ function. The result is equivalent to:
This method was added in v1.84 of Math::BigInt (April 2007).
-=head2 bpi()
+=item bpi()
- print Math::BigInt->bpi(100), "\n"; # 3
+ print Math::BigInt->bpi(100), "\n"; # 3
Returns PI truncated to an integer, with the argument being ignored. This means
under BigInt this always returns C<3>.
@@ -4003,17 +4013,17 @@ under BigInt this always returns C<3>.
If upgrading is in effect, returns PI, rounded to N digits with the
current rounding mode:
- use Math::BigFloat;
- use Math::BigInt upgrade => Math::BigFloat;
- print Math::BigInt->bpi(3), "\n"; # 3.14
- print Math::BigInt->bpi(100), "\n"; # 3.1415....
+ use Math::BigFloat;
+ use Math::BigInt upgrade => Math::BigFloat;
+ print Math::BigInt->bpi(3), "\n"; # 3.14
+ print Math::BigInt->bpi(100), "\n"; # 3.1415....
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bcos()
+=item bcos()
- my $x = Math::BigInt->new(1);
- print $x->bcos(100), "\n";
+ my $x = Math::BigInt->new(1);
+ print $x->bcos(100), "\n";
Calculate the cosinus of $x, modifying $x in place.
@@ -4022,10 +4032,10 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bsin()
+=item bsin()
- my $x = Math::BigInt->new(1);
- print $x->bsin(100), "\n";
+ my $x = Math::BigInt->new(1);
+ print $x->bsin(100), "\n";
Calculate the sinus of $x, modifying $x in place.
@@ -4034,11 +4044,11 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan2()
+=item batan2()
- my $x = Math::BigInt->new(1);
- my $y = Math::BigInt->new(1);
- print $y->batan2($x), "\n";
+ my $x = Math::BigInt->new(1);
+ my $y = Math::BigInt->new(1);
+ print $y->batan2($x), "\n";
Calculate the arcus tangens of C<$y> divided by C<$x>, modifying $y in place.
@@ -4047,10 +4057,10 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan()
+=item batan()
- my $x = Math::BigFloat->new(0.5);
- print $x->batan(100), "\n";
+ my $x = Math::BigFloat->new(0.5);
+ print $x->batan(100), "\n";
Calculate the arcus tangens of $x, modifying $x in place.
@@ -4059,60 +4069,60 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 blsft()
+=item blsft()
- $x->blsft($y); # left shift in base 2
- $x->blsft($y,$n); # left shift, in base $n (like 10)
+ $x->blsft($y); # left shift in base 2
+ $x->blsft($y,$n); # left shift, in base $n (like 10)
-=head2 brsft()
+=item brsft()
- $x->brsft($y); # right shift in base 2
- $x->brsft($y,$n); # right shift, in base $n (like 10)
+ $x->brsft($y); # right shift in base 2
+ $x->brsft($y,$n); # right shift, in base $n (like 10)
-=head2 band()
+=item band()
- $x->band($y); # bitwise and
+ $x->band($y); # bitwise and
-=head2 bior()
+=item bior()
- $x->bior($y); # bitwise inclusive or
+ $x->bior($y); # bitwise inclusive or
-=head2 bxor()
+=item bxor()
- $x->bxor($y); # bitwise exclusive or
+ $x->bxor($y); # bitwise exclusive or
-=head2 bnot()
+=item bnot()
- $x->bnot(); # bitwise not (two's complement)
+ $x->bnot(); # bitwise not (two's complement)
-=head2 bsqrt()
+=item bsqrt()
- $x->bsqrt(); # calculate square-root
+ $x->bsqrt(); # calculate square-root
-=head2 broot()
+=item broot()
- $x->broot($N);
+ $x->broot($N);
Calculates the N'th root of C<$x>.
-=head2 bfac()
+=item bfac()
- $x->bfac(); # factorial of $x (1*2*3*4*..$x)
+ $x->bfac(); # factorial of $x (1*2*3*4*..$x)
-=head2 round()
+=item round()
- $x->round($A,$P,$round_mode);
+ $x->round($A,$P,$round_mode);
Round $x to accuracy C<$A> or precision C<$P> using the round mode
C<$round_mode>.
-=head2 bround()
+=item bround()
- $x->bround($N); # accuracy: preserve $N digits
+ $x->bround($N); # accuracy: preserve $N digits
-=head2 bfround()
+=item bfround()
- $x->bfround($N);
+ $x->bfround($N);
If N is > 0, rounds to the Nth digit from the left. If N < 0, rounds to
the Nth digit after the dot. Since BigInts are integers, the case N < 0
@@ -4127,60 +4137,69 @@ Examples:
123456.123456 -2 123456.12
123456.123456 -3 123456.123
-=head2 bfloor()
+=item bfloor()
+
+ $x->bfloor();
- $x->bfloor();
+Round $x towards minus infinity (i.e., set $x to the largest integer less than
+or equal to $x). This is a no-op in BigInt, but changes $x in BigFloat, if $x
+is not an integer.
-Set $x to the integer less or equal than $x. This is a no-op in BigInt, but
-does change $x in BigFloat.
+=item bceil()
-=head2 bceil()
+ $x->bceil();
- $x->bceil();
+Round $x towards plus infinity (i.e., set $x to the smallest integer greater
+than or equal to $x). This is a no-op in BigInt, but changes $x in BigFloat, if
+$x is not an integer.
-Set $x to the integer greater or equal than $x. This is a no-op in BigInt, but
-does change $x in BigFloat.
+=item bint()
-=head2 bgcd()
+ $x->bint();
- bgcd(@values); # greatest common divisor (no OO style)
+Round $x towards zero. This is a no-op in BigInt, but changes $x in BigFloat,
+if $x is not an integer.
-=head2 blcm()
+=item bgcd()
- blcm(@values); # lowest common multiple (no OO style)
+ bgcd(@values); # greatest common divisor (no OO style)
-head2 length()
+=item blcm()
- $x->length();
- ($xl,$fl) = $x->length();
+ blcm(@values); # lowest common multiple (no OO style)
+
+=item length()
+
+ $x->length();
+ ($xl,$fl) = $x->length();
Returns the number of digits in the decimal representation of the number.
In list context, returns the length of the integer and fraction part. For
BigInt's, the length of the fraction part will always be 0.
-=head2 exponent()
+=item exponent()
- $x->exponent();
+ $x->exponent();
Return the exponent of $x as BigInt.
-=head2 mantissa()
+=item mantissa()
- $x->mantissa();
+ $x->mantissa();
Return the signed mantissa of $x as BigInt.
-=head2 parts()
+=item parts()
- $x->parts(); # return (mantissa,exponent) as BigInt
+ $x->parts(); # return (mantissa,exponent) as BigInt
-=head2 copy()
+=item copy()
- $x->copy(); # make a true copy of $x (unlike $y = $x;)
+ $x->copy(); # make a true copy of $x (unlike $y = $x;)
-=head2 as_int()/as_number()
+=item as_int()/as_number()
- $x->as_int();
+ $x->as_int();
Returns $x as a BigInt (truncated towards zero). In BigInt this is the same as
C<copy()>.
@@ -4188,29 +4207,29 @@ C<copy()>.
C<as_number()> is an alias to this method. C<as_number> was introduced in
v1.22, while C<as_int()> was only introduced in v1.68.
-=head2 bstr()
+=item bstr()
- $x->bstr();
+ $x->bstr();
Returns a normalized string representation of C<$x>.
-=head2 bsstr()
+=item bsstr()
- $x->bsstr(); # normalized string in scientific notation
+ $x->bsstr(); # normalized string in scientific notation
-=head2 as_hex()
+=item as_hex()
- $x->as_hex(); # as signed hexadecimal string with prefixed 0x
+ $x->as_hex(); # as signed hexadecimal string with prefixed 0x
-=head2 as_bin()
+=item as_bin()
- $x->as_bin(); # as signed binary string with prefixed 0b
+ $x->as_bin(); # as signed binary string with prefixed 0b
-=head2 as_oct()
+=item as_oct()
- $x->as_oct(); # as signed octal string with prefixed 0
+ $x->as_oct(); # as signed octal string with prefixed 0
-=head2 numify()
+=item numify()
print $x->numify();
@@ -4219,16 +4238,16 @@ whenever a scalar is needed, for instance in array index operations.
This loses precision, to avoid this use L<as_int()|/"as_int()/as_number()"> instead.
-=head2 modify()
+=item modify()
- $x->modify('bpowd');
+ $x->modify('bpowd');
This method returns 0 if the object can be modified with the given
operation, or 1 if not.
This is used for instance by L<Math::BigInt::Constant>.
-=head2 upgrade()/downgrade()
+=item upgrade()/downgrade()
Set/get the class for downgrade/upgrade operations. Thuis is used
for instance by L<bignum>. The defaults are '', thus the following
@@ -4239,15 +4258,17 @@ operation will create a BigInt, not a BigFloat:
print $i + $f,"\n"; # print 246
-=head2 div_scale()
+=item div_scale()
Set/get the number of digits for the default precision in divide
operations.
-=head2 round_mode()
+=item round_mode()
Set/get the current round mode.
+=back
+
=head1 ACCURACY and PRECISION
Since version v1.33, Math::BigInt and Math::BigFloat have full support for
@@ -4320,7 +4341,7 @@ When rounding a number, different 'styles' or 'kinds'
of rounding are possible. (Note that random rounding, as in
Math::Round, is not implemented.)
-=over 2
+=over
=item 'trunc'
@@ -4385,7 +4406,7 @@ is 5 or greater, otherwise round down. E.g., 0.15 becomes 0.2 and
The handling of A & P in MBI/MBF (the old core code shipped with Perl
versions <= 5.7.2) is like this:
-=over 2
+=over
=item Precision
@@ -4397,14 +4418,15 @@ versions <= 5.7.2) is like this:
* fround($a) rounds to $a significant digits
* only fdiv() and fsqrt() take A as (optional) parameter
- + other operations simply create the same number (fneg etc), or more (fmul)
- of digits
- + rounding/truncating is only done when explicitly calling one of fround
- or ffround, and never for BigInt (not implemented)
+ + other operations simply create the same number (fneg etc), or
+ more (fmul) of digits
+ + rounding/truncating is only done when explicitly calling one
+ of fround or ffround, and never for BigInt (not implemented)
* fsqrt() simply hands its accuracy argument over to fdiv.
- * the documentation and the comment in the code indicate two different ways
- on how fdiv() determines the maximum number of digits it should calculate,
- and the actual code does yet another thing
+ * the documentation and the comment in the code indicate two
+ different ways on how fdiv() determines the maximum number
+ of digits it should calculate, and the actual code does yet
+ another thing
POD:
max($Math::BigFloat::div_scale,length(dividend)+length(divisor))
Comment:
@@ -4412,16 +4434,18 @@ versions <= 5.7.2) is like this:
Actual code:
scale = max(scale, length(dividend)-1,length(divisor)-1);
scale += length(divisor) - length(dividend);
- So for lx = 3, ly = 9, scale = 10, scale will actually be 16 (10+9-3).
- Actually, the 'difference' added to the scale is calculated from the
- number of "significant digits" in dividend and divisor, which is derived
- by looking at the length of the mantissa. Which is wrong, since it includes
- the + sign (oops) and actually gets 2 for '+100' and 4 for '+101'. Oops
- again. Thus 124/3 with div_scale=1 will get you '41.3' based on the strange
- assumption that 124 has 3 significant digits, while 120/7 will get you
- '17', not '17.1' since 120 is thought to have 2 significant digits.
- The rounding after the division then uses the remainder and $y to determine
- whether it must round up or down.
+ So for lx = 3, ly = 9, scale = 10, scale will actually be 16 (10
+ So for lx = 3, ly = 9, scale = 10, scale will actually be 16
+ (10+9-3). Actually, the 'difference' added to the scale is cal-
+ culated from the number of "significant digits" in dividend and
+ divisor, which is derived by looking at the length of the man-
+ tissa. Which is wrong, since it includes the + sign (oops) and
+ actually gets 2 for '+100' and 4 for '+101'. Oops again. Thus
+ 124/3 with div_scale=1 will get you '41.3' based on the strange
+ assumption that 124 has 3 significant digits, while 120/7 will
+ get you '17', not '17.1' since 120 is thought to have 2 signif-
+ icant digits. The rounding after the division then uses the
+ remainder and $y to determine whether it must round up or down.
? I have no idea which is the right way. That's why I used a slightly more
? simple scheme and tweaked the few failing testcases to match it.
@@ -4429,7 +4453,7 @@ versions <= 5.7.2) is like this:
This is how it works now:
-=over 2
+=over
=item Setting/Accessing
@@ -4611,7 +4635,7 @@ This is how it works now:
While BigInt has extensive handling of inf and NaN, certain quirks remain.
-=over 2
+=over
=item oct()/hex()
@@ -4744,16 +4768,16 @@ change.
use Math::BigInt;
- sub bint { Math::BigInt->new(shift); }
+ sub bigint { Math::BigInt->new(shift); }
$x = Math::BigInt->bstr("1234") # string "1234"
$x = "$x"; # same as bstr()
$x = Math::BigInt->bneg("1234"); # BigInt "-1234"
$x = Math::BigInt->babs("-12345"); # BigInt "12345"
$x = Math::BigInt->bnorm("-0.00"); # BigInt "0"
- $x = bint(1) + bint(2); # BigInt "3"
- $x = bint(1) + "2"; # ditto (auto-BigIntify of "2")
- $x = bint(1); # BigInt "1"
+ $x = bigint(1) + bigint(2); # BigInt "3"
+ $x = bigint(1) + "2"; # ditto (auto-BigIntify of "2")
+ $x = bigint(1); # BigInt "1"
$x = $x + 5 / 2; # BigInt "3"
$x = $x ** 3; # BigInt "27"
$x *= 2; # BigInt "54"
@@ -4795,13 +4819,13 @@ Examples for converting:
After C<use Math::BigInt ':constant'> all the B<integer> decimal, hexadecimal
and binary constants in the given scope are converted to C<Math::BigInt>.
-This conversion happens at compile time.
+This conversion happens at compile time.
In particular,
perl -MMath::BigInt=:constant -e 'print 2**100,"\n"'
-prints the integer value of C<2**100>. Note that without conversion of
+prints the integer value of C<2**100>. Note that without conversion of
constants the expression 2**100 will be calculated as perl scalar.
Please note that strings and floating point constants are not affected,
@@ -4862,7 +4886,7 @@ C<babs()> etc), instead of O(N) and thus nearly always take much less time.
These optimizations were done on purpose.
If you find the Calc module to slow, try to install any of the replacement
-modules and see if they help you.
+modules and see if they help you.
=head2 Alternative math libraries
@@ -4878,7 +4902,7 @@ For more benchmark results see L<http://bloodgate.com/perl/benchmarks.html>.
The basic design of Math::BigInt allows simple subclasses with very little
work, as long as a few simple rules are followed:
-=over 2
+=over
=item *
@@ -4903,7 +4927,7 @@ to support different storage methods.
More complex sub-classes may have to replicate more of the logic internal of
Math::BigInt if they need to change more basic behaviors. A subclass that
-needs to merely change the output only needs to overload C<bstr()>.
+needs to merely change the output only needs to overload C<bstr()>.
All other object methods and overloaded functions can be directly inherited
from the parent class.
@@ -4924,11 +4948,11 @@ auto-upgrading and auto-downgrading to work correctly:
$upgrade = undef;
$downgrade = undef;
-This allows Math::BigInt to correctly retrieve package globals from the
+This allows Math::BigInt to correctly retrieve package globals from the
subclass, like C<$SubClass::precision>. See t/Math/BigInt/Subclass.pm or
t/Math/BigFloat/SubClass.pm completely functional subclass examples.
-Don't forget to
+Don't forget to
use overload;
@@ -4947,7 +4971,7 @@ the class Foo::Bar. Usually this is used in conjunction with Math::BigFloat:
use Math::BigInt upgrade => 'Math::BigFloat';
-As a shortcut, you can use the module C<bignum>:
+As a shortcut, you can use the module L<bignum>:
use bignum;
@@ -4965,7 +4989,7 @@ Beware: This feature is not fully implemented yet.
The following methods upgrade themselves unconditionally; that is if upgrade
is in effect, they will always hand up their work:
-=over 2
+=over
=item bsqrt()
@@ -4995,7 +5019,7 @@ C<Math::BigInt> exports nothing by default, but can export the following methods
Some things might not work as you expect them. Below is documented what is
known to be troublesome:
-=over 1
+=over
=item bstr(), bsstr() and 'cmp'
@@ -5003,13 +5027,13 @@ Both C<bstr()> and C<bsstr()> as well as automated stringify via overload now
drop the leading '+'. The old code would return '+3', the new returns '3'.
This is to be consistent with Perl and to make C<cmp> (especially with
overloading) to work as you expect. It also solves problems with C<Test.pm>,
-because its C<ok()> uses 'eq' internally.
+because its C<ok()> uses 'eq' internally.
Mark Biggar said, when asked about to drop the '+' altogether, or make only
C<cmp> work:
I agree (with the first alternative), don't add the '+' on positive
- numbers. It's not as important anymore with the new internal
+ numbers. It's not as important anymore with the new internal
form for numbers. It made doing things like abs and neg easier,
but those have to be done differently now anyway.
@@ -5036,7 +5060,7 @@ Additionally, the following still works:
There is now a C<bsstr()> method to get the string in scientific notation aka
C<1e+2> instead of C<100>. Be advised that overloaded 'eq' always uses bstr()
for comparison, but Perl will represent some numbers as 100 and others
-as 1e+308. If in doubt, convert both arguments to Math::BigInt before
+as 1e+308. If in doubt, convert both arguments to Math::BigInt before
comparing them as strings:
use Test;
@@ -5049,7 +5073,7 @@ comparing them as strings:
$y = Math::BigInt->new($y);
ok ($x,$y); # okay
-Alternatively, simple use C<< <=> >> for comparisons, this will get it
+Alternatively, simply use C<< <=> >> for comparisons, this will get it
always right. There is not yet a way to get a number automatically represented
as a string that matches exactly the way Perl represents it.
@@ -5058,7 +5082,7 @@ comparing NaNs.
=item int()
-C<int()> will return (at least for Perl v5.7.1 and up) another BigInt, not a
+C<int()> will return (at least for Perl v5.7.1 and up) another BigInt, not a
Perl scalar:
$x = Math::BigInt->new(123);
@@ -5084,7 +5108,7 @@ when you access an array:
$z = $array[$x]; # does work automatically
-=item length
+=item length()
The following will probably not do what you expect:
@@ -5092,11 +5116,11 @@ The following will probably not do what you expect:
print $c->length(),"\n"; # prints 30
It prints both the number of digits in the number and in the fraction part
-since print calls C<length()> in list context. Use something like:
+since print calls C<length()> in list context. Use something like:
print scalar $c->length(),"\n"; # prints 3
-=item bdiv
+=item bdiv()
The following will probably not do what you expect:
@@ -5107,9 +5131,10 @@ context. Also, C<bdiv()> will modify $c, so be careful. You probably want
to use
print $c / 10000,"\n";
- print scalar $c->bdiv(10000),"\n"; # or if you want to modify $c
-instead.
+or, if you want to modify $c instead,
+
+ print scalar $c->bdiv(10000),"\n";
The quotient is always the greatest integer less than or equal to the
real-valued quotient of the two operands, and the remainder (when it is
@@ -5248,7 +5273,7 @@ With overloaded math, only the first two variants will result in a BigFloat:
use Math::BigInt;
use Math::BigFloat;
-
+
$mbf = Math::BigFloat->new(5);
$mbi2 = Math::BigInteger->new(5);
$mbi = Math::BigInteger->new(2);
@@ -5319,6 +5344,65 @@ For negative numbers in base see also L<brsft|/brsft()>.
=back
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-math-bigint at rt.cpan.org>, or through the web interface at
+L<https://rt.cpan.org/Ticket/Create.html?Queue=Math-BigInt>
+(requires login).
+We will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Math::BigInt
+
+You can also look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<https://rt.cpan.org/Public/Dist/Display.html?Name=Math-BigInt>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Math-BigInt>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/dist/Math-BigInt>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Math-BigInt/>
+
+=item * CPAN Testers Matrix
+
+L<http://matrix.cpantesters.org/?dist=Math-BigInt>
+
+=item * The Bignum mailing list
+
+=over 4
+
+=item * Post to mailing list
+
+C<bignum at lists.scsys.co.uk>
+
+=item * View mailing list
+
+L<http://lists.scsys.co.uk/pipermail/bignum/>
+
+=item * Subscribe/Unsubscribe
+
+L<http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/bignum>
+
+=back
+
+=back
+
=head1 LICENSE
This program is free software; you may redistribute it and/or modify it under
@@ -5326,17 +5410,12 @@ the same terms as Perl itself.
=head1 SEE ALSO
-L<Math::BigFloat>, L<Math::BigRat> and L<Math::Big> as well as
-L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and L<Math::BigInt::GMP>.
+L<Math::BigFloat> and L<Math::BigRat> as well as the backends
+L<Math::BigInt::FastCalc>, L<Math::BigInt::GMP>, and L<Math::BigInt::Pari>.
The pragmas L<bignum>, L<bigint> and L<bigrat> also might be of interest
because they solve the autoupgrading/downgrading issue, at least partly.
-The package at
-L<http://search.cpan.org/search?mode=module&query=Math%3A%3ABigInt> contains
-more documentation including a full version history, testcases, empty
-subclass files and benchmarks.
-
=head1 AUTHORS
Original code by Mark Biggar, overloaded interface by Ilya Zakharevich.