⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bignum.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
C<use bigint;>:        perl -Mbigint -le 'print 1234.5+4.5'        1238There is also C<use bigrat;> which gives you big rationals:        perl -Mbigrat -le 'print 1234+4.1'        12381/10The entire upgrading/downgrading is still experimental and might not workas you expect or may even have bugs. You might get errors like this:        Can't use an undefined value as an ARRAY reference at        /usr/local/lib/perl5/5.8.0/Math/BigInt/Calc.pm line 864This means somewhere a routine got a BigFloat/Lite but expected a BigInt (orvice versa) and the upgrade/downgrad path was missing. This is a bug, pleasereport it so that we can fix it.You might consider using just Math::BigInt or Math::BigFloat, since theyallow you finer control over what get's done in which module/space. Forinstance, simple loop counters will be Math::BigInts under C<use bignum;> andthis is slower than keeping them as Perl scalars:        perl -Mbignum -le 'for ($i = 0; $i < 10; $i++) { print ref($i); }'Please note the following does not work as expected (prints nothing), sinceoverloading of '..' is not yet possible in Perl (as of v5.8.0):        perl -Mbignum -le 'for (1..2) { print ref($_); }'=head2 Optionsbignum recognizes some options that can be passed while loading it via use.The options can (currently) be either a single letter form, or the long form.The following options exist:=over 2=item a or accuracyThis sets the accuracy for all math operations. The argument must be greaterthan or equal to zero. See Math::BigInt's bround() function for details.	perl -Mbignum=a,50 -le 'print sqrt(20)'Note that setting precision and accurary at the same time is not possible.=item p or precisionThis sets the precision for all math operations. The argument can be anyinteger. Negative values mean a fixed number of digits after the dot, whilea positive value rounds to this digit left from the dot. 0 or 1 mean round tointeger. See Math::BigInt's bfround() function for details.	perl -Mbignum=p,-50 -le 'print sqrt(20)'Note that setting precision and accurary at the same time is not possible.=item t or traceThis enables a trace mode and is primarily for debugging bignum orMath::BigInt/Math::BigFloat.=item l or libLoad a different math lib, see L<MATH LIBRARY>.	perl -Mbignum=l,GMP -e 'print 2 ** 512'Currently there is no way to specify more than one library on the commandline. This means the following does not work:	perl -Mbignum=l,GMP,Pari -e 'print 2 ** 512'This will be hopefully fixed soon ;)=item hexOverride the built-in hex() method with a version that can handle bigintegers. Note that under Perl older than v5.9.4, this will be globaland cannot be disabled with "no bigint;".=item octOverride the built-in oct() method with a version that can handle bigintegers. Note that under Perl older than v5.9.4, this will be globaland cannot be disabled with "no bigint;".=item v or versionThis prints out the name and version of all modules used and then exits.	perl -Mbignum=v=back=head2 MethodsBeside import() and AUTOLOAD() there are only a few other methods.Since all numbers are now objects, you can use all functions that are part ofthe BigInt or BigFloat API. It is wise to use only the bxxx() notation, and notthe fxxx() notation, though. This makes it possible that the underlying objectmight morph into a different class than BigFloat.=head2 CaveatsBut a warning is in order. When using the following to make a copy of a number,only a shallow copy will be made.        $x = 9; $y = $x;        $x = $y = 7;If you want to make a real copy, use the following:        $y = $x->copy();Using the copy or the original with overloaded math is okay, e.g. thefollowing work:        $x = 9; $y = $x;        print $x + 1, " ", $y,"\n";     # prints 10 9but calling any method that modifies the number directly will result inB<both> the original and the copy being destroyed:        $x = 9; $y = $x;        print $x->badd(1), " ", $y,"\n";        # prints 10 10        $x = 9; $y = $x;        print $x->binc(1), " ", $y,"\n";        # prints 10 10        $x = 9; $y = $x;        print $x->bmul(2), " ", $y,"\n";        # prints 18 18Using methods that do not modify, but test the contents works:        $x = 9; $y = $x;        $z = 9 if $x->is_zero();                # works fineSee the documentation about the copy constructor and C<=> in overload, aswell as the documentation in BigInt for further details.=over 2=item inf()A shortcut to return Math::BigInt->binf(). Useful because Perl does not alwayshandle bareword C<inf> properly.=item NaN()A shortcut to return Math::BigInt->bnan(). Useful because Perl does not alwayshandle bareword C<NaN> properly.=item e	# perl -Mbignum=e -wle 'print e'Returns Euler's number C<e>, aka exp(1).=item PI()	# perl -Mbignum=PI -wle 'print PI'Returns PI.=item bexp()	bexp($power,$accuracy);Returns Euler's number C<e> raised to the appropriate power, tothe wanted accuracy.Example:	# perl -Mbignum=bexp -wle 'print bexp(1,80)'=item bpi()	bpi($accuracy);Returns PI to the wanted accuracy.Example:	# perl -Mbignum=bpi -wle 'print bpi(80)'=item upgrade()Return the class that numbers are upgraded to, is in fact returningC<$Math::BigInt::upgrade>.=item in_effect()	use bignum;	print "in effect\n" if bignum::in_effect;	# true	{	  no bignum;	  print "in effect\n" if bignum::in_effect;	# false	}Returns true or false if C<bignum> is in effect in the current scope.This method only works on Perl v5.9.4 or later.=back=head2 Math LibraryMath with the numbers is done (by default) by a module calledMath::BigInt::Calc. This is equivalent to saying:	use bignum lib => 'Calc';You can change this by using:	use bignum lib => 'GMP';The following would first try to find Math::BigInt::Foo, thenMath::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:	use bignum lib => 'Foo,Math::BigInt::Bar';Please see respective module documentation for further details.Using C<lib> warns if none of the specified libraries can be found andL<Math::BigInt> did fall back to one of the default libraries.To supress this warning, use C<try> instead:	use bignum try => 'GMP';If you want the code to die instead of falling back, use C<only> instead:	use bignum only => 'GMP';=head2 INTERNAL FORMATThe numbers are stored as objects, and their internals might change at anytime,especially between math operations. The objects also might belong to differentclasses, like Math::BigInt, or Math::BigFLoat. Mixing them together, evenwith normal scalars is not extraordinary, but normal and expected.You should not depend on the internal format, all accesses must go throughaccessor methods. E.g. looking at $x->{sign} is not a bright idea since thereis no guaranty that the object in question has such a hashkey, nor is a hashunderneath at all.=head2 SIGNThe sign is either '+', '-', 'NaN', '+inf' or '-inf' and stored seperately.You can access it with the sign() method.A sign of 'NaN' is used to represent the result when input arguments are notnumbers or as a result of 0/0. '+inf' and '-inf' represent plus respectivelyminus infinity. You will get '+inf' when dividing a positive number by 0, and'-inf' when dividing any negative number by 0.=head1 CAVAETS=over 2=item in_effect()This method only works on Perl v5.9.4 or later.=item hex()/oct()C<bigint> overrides these routines with versions that can also handlebig integer values. Under Perl prior to version v5.9.4, however, thiswill not happen unless you specifically ask for it with the twoimport tags "hex" and "oct" - and then it will be global and cannot bedisabled inside a scope with "no bigint":	use bigint qw/hex oct/;	print hex("0x1234567890123456");	{		no bigint;		print hex("0x1234567890123456");	}The second call to hex() will warn about a non-portable constant.Compare this to:	use bigint;	# will warn only under older than v5.9.4	print hex("0x1234567890123456");=back=head1 MODULES USEDC<bignum> is just a thin wrapper around various modules of the Math::BigIntfamily. Think of it as the head of the family, who runs the shop, and ordersthe others to do the work.The following modules are currently used by bignum:	Math::BigInt::Lite	(for speed, and only if it is loadable)	Math::BigInt	Math::BigFloat=head1 EXAMPLESSome cool command line examples to impress the Python crowd ;) 	perl -Mbignum -le 'print sqrt(33)'	perl -Mbignum -le 'print 2*255'	perl -Mbignum -le 'print 4.5+2*255'	perl -Mbignum -le 'print 3/7 + 5/7 + 8/3'	perl -Mbignum -le 'print 123->is_odd()'	perl -Mbignum -le 'print log(2)'	perl -Mbignum -le 'print exp(1)'	perl -Mbignum -le 'print 2 ** 0.5'	perl -Mbignum=a,65 -le 'print 2 ** 0.2'	perl -Mbignum=a,65,l,GMP -le 'print 7 ** 7777'=head1 LICENSEThis program is free software; you may redistribute it and/or modify it underthe same terms as Perl itself.=head1 SEE ALSOEspecially L<bigrat> as in C<perl -Mbigrat -le 'print 1/3+1/4'>.L<Math::BigFloat>, L<Math::BigInt>, L<Math::BigRat> and L<Math::Big> as wellas L<Math::BigInt::BitVect>, L<Math::BigInt::Pari> and  L<Math::BigInt::GMP>.=head1 AUTHORS(C) by Tels L<http://bloodgate.com/> in early 2002 - 2007.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -