📄 math::bigrat.3
字号:
\& my $h = Math::BigRat\->from_hex(\*(Aq0x10\*(Aq);\& my $b = Math::BigRat\->from_bin(\*(Aq0b10000000\*(Aq);\& my $o = Math::BigRat\->from_oct(\*(Aq020\*(Aq);.Ve.PPCreate a BigRat from an hexadecimal, binary or octal numberin string form..Sh "\fIlength()\fP".IX Subsection "length()".Vb 1\& $len = $x\->length();.Ve.PPReturn the length of \f(CW$x\fR in digitis for integer values..Sh "\fIdigit()\fP".IX Subsection "digit()".Vb 2\& print Math::BigRat\->new(\*(Aq123/1\*(Aq)\->digit(1); # 1\& print Math::BigRat\->new(\*(Aq123/1\*(Aq)\->digit(\-1); # 3.Ve.PPReturn the N'ths digit from X when X is an integer value..Sh "\fIbnorm()\fP".IX Subsection "bnorm()".Vb 1\& $x\->bnorm();.Ve.PPReduce the number to the shortest form. This routine is calledautomatically whenever it is needed..Sh "\fIbfac()\fP".IX Subsection "bfac()".Vb 1\& $x\->bfac();.Ve.PPCalculates the factorial of \f(CW$x\fR. For instance:.PP.Vb 2\& print Math::BigRat\->new(\*(Aq3/1\*(Aq)\->bfac(),"\en"; # 1*2*3\& print Math::BigRat\->new(\*(Aq5/1\*(Aq)\->bfac(),"\en"; # 1*2*3*4*5.Ve.PPWorks currently only for integers..Sh "\fIbround()\fP/\fIround()\fP/\fIbfround()\fP".IX Subsection "bround()/round()/bfround()"Are not yet implemented..Sh "\fIbmod()\fP".IX Subsection "bmod()".Vb 4\& use Math::BigRat;\& my $x = Math::BigRat\->new(\*(Aq7/4\*(Aq);\& my $y = Math::BigRat\->new(\*(Aq4/3\*(Aq);\& print $x\->bmod($y);.Ve.PPSet \f(CW$x\fR to the remainder of the division of \f(CW$x\fR by \f(CW$y\fR..Sh "\fIbneg()\fP".IX Subsection "bneg()".Vb 1\& $x\->bneg();.Ve.PPUsed to negate the object in-place..Sh "\fIis_one()\fP".IX Subsection "is_one()".Vb 1\& print "$x is 1\en" if $x\->is_one();.Ve.PPReturn true if \f(CW$x\fR is exactly one, otherwise false..Sh "\fIis_zero()\fP".IX Subsection "is_zero()".Vb 1\& print "$x is 0\en" if $x\->is_zero();.Ve.PPReturn true if \f(CW$x\fR is exactly zero, otherwise false..Sh "\fIis_pos()\fP/\fIis_positive()\fP".IX Subsection "is_pos()/is_positive()".Vb 1\& print "$x is >= 0\en" if $x\->is_positive();.Ve.PPReturn true if \f(CW$x\fR is positive (greater than or equal to zero), otherwisefalse. Please note that '+inf' is also positive, while 'NaN' and '\-inf' aren't..PP\&\f(CW\*(C`is_positive()\*(C'\fR is an alias for \f(CW\*(C`is_pos()\*(C'\fR..Sh "\fIis_neg()\fP/\fIis_negative()\fP".IX Subsection "is_neg()/is_negative()".Vb 1\& print "$x is < 0\en" if $x\->is_negative();.Ve.PPReturn true if \f(CW$x\fR is negative (smaller than zero), otherwise false. Pleasenote that '\-inf' is also negative, while 'NaN' and '+inf' aren't..PP\&\f(CW\*(C`is_negative()\*(C'\fR is an alias for \f(CW\*(C`is_neg()\*(C'\fR..Sh "\fIis_int()\fP".IX Subsection "is_int()".Vb 1\& print "$x is an integer\en" if $x\->is_int();.Ve.PPReturn true if \f(CW$x\fR has a denominator of 1 (e.g. no fraction parts), otherwisefalse. Please note that '\-inf', 'inf' and 'NaN' aren't integer..Sh "\fIis_odd()\fP".IX Subsection "is_odd()".Vb 1\& print "$x is odd\en" if $x\->is_odd();.Ve.PPReturn true if \f(CW$x\fR is odd, otherwise false..Sh "\fIis_even()\fP".IX Subsection "is_even()".Vb 1\& print "$x is even\en" if $x\->is_even();.Ve.PPReturn true if \f(CW$x\fR is even, otherwise false..Sh "\fIbceil()\fP".IX Subsection "bceil()".Vb 1\& $x\->bceil();.Ve.PPSet \f(CW$x\fR to the next bigger integer value (e.g. truncate the number to integerand then increment it by one)..Sh "\fIbfloor()\fP".IX Subsection "bfloor()".Vb 1\& $x\->bfloor();.Ve.PPTruncate \f(CW$x\fR to an integer value..Sh "\fIbsqrt()\fP".IX Subsection "bsqrt()".Vb 1\& $x\->bsqrt();.Ve.PPCalculate the square root of \f(CW$x\fR..Sh "\fIbroot()\fP".IX Subsection "broot()".Vb 1\& $x\->broot($n);.Ve.PPCalculate the N'th root of \f(CW$x\fR..Sh "\fIbadd()\fP/\fIbmul()\fP/\fIbsub()\fP/\fIbdiv()\fP/\fIbdec()\fP/\fIbinc()\fP".IX Subsection "badd()/bmul()/bsub()/bdiv()/bdec()/binc()"Please see the documentation in Math::BigInt..Sh "\fIcopy()\fP".IX Subsection "copy()".Vb 1\& my $z = $x\->copy();.Ve.PPMakes a deep copy of the object..PPPlease see the documentation in Math::BigInt for further details..Sh "\fIbstr()\fP/\fIbsstr()\fP".IX Subsection "bstr()/bsstr()".Vb 3\& my $x = Math::BigInt\->new(\*(Aq8/4\*(Aq);\& print $x\->bstr(),"\en"; # prints 1/2\& print $x\->bsstr(),"\en"; # prints 1/2.Ve.PPReturn a string representating this object..Sh "\fIbacmp()\fP/\fIbcmp()\fP".IX Subsection "bacmp()/bcmp()"Used to compare numbers..PPPlease see the documentation in Math::BigInt for further details..Sh "\fIblsft()\fP/\fIbrsft()\fP".IX Subsection "blsft()/brsft()"Used to shift numbers left/right..PPPlease see the documentation in Math::BigInt for further details..Sh "\fIbpow()\fP".IX Subsection "bpow()".Vb 1\& $x\->bpow($y);.Ve.PPCompute \f(CW$x\fR ** \f(CW$y\fR..PPPlease see the documentation in Math::BigInt for further details..Sh "\fIbexp()\fP".IX Subsection "bexp()".Vb 1\& $x\->bexp($accuracy); # calculate e ** X.Ve.PPCalculates two integers A and B so that A/B is equal to \f(CW\*(C`e ** $x\*(C'\fR, where \f(CW\*(C`e\*(C'\fR isEuler's number..PPThis method was added in v0.20 of Math::BigRat (May 2007)..PPSee also \fIblog()\fR..Sh "\fIbnok()\fP".IX Subsection "bnok()".Vb 1\& $x\->bnok($y); # x over y (binomial coefficient n over k).Ve.PPCalculates the binomial coefficient n over k, also called the \*(L"choose\*(R"function. The result is equivalent to:.PP.Vb 3\& ( n ) n!\& | \- | = \-\-\-\-\-\-\-\& ( k ) k!(n\-k)!.Ve.PPThis method was added in v0.20 of Math::BigRat (May 2007)..Sh "\fIconfig()\fP".IX Subsection "config()".Vb 1\& use Data::Dumper;\&\& print Dumper ( Math::BigRat\->config() );\& print Math::BigRat\->config()\->{lib},"\en";.Ve.PPReturns a hash containing the configuration, e.g. the version number, libloaded etc. The following hash keys are currently filled in with theappropriate information..PP.Vb 10\& key RO/RW Description\& Example\& ============================================================\& lib RO Name of the Math library\& Math::BigInt::Calc\& lib_version RO Version of \*(Aqlib\*(Aq\& 0.30\& class RO The class of config you just called\& Math::BigRat\& version RO version number of the class you used\& 0.10\& upgrade RW To which class numbers are upgraded\& undef\& downgrade RW To which class numbers are downgraded\& undef\& precision RW Global precision\& undef\& accuracy RW Global accuracy\& undef\& round_mode RW Global round mode\& even\& div_scale RW Fallback accuracy for div\& 40\& trap_nan RW Trap creation of NaN (undef = no)\& undef\& trap_inf RW Trap creation of +inf/\-inf (undef = no)\& undef.Ve.PPBy passing a reference to a hash you may set the configuration values. Thisworks only for values that a marked with a \f(CW\*(C`RW\*(C'\fR above, anything else isread-only..SH "BUGS".IX Header "BUGS"Some things are not yet implemented, or only implemented half-way:.IP "inf handling (partial)" 2.IX Item "inf handling (partial)".PD 0.IP "NaN handling (partial)" 2.IX Item "NaN handling (partial)".IP "rounding (not implemented except for bceil/bfloor)" 2.IX Item "rounding (not implemented except for bceil/bfloor)".ie n .IP "$x\fR ** \f(CW$y\fR where \f(CW$y is not an integer" 2.el .IP "\f(CW$x\fR ** \f(CW$y\fR where \f(CW$y\fR is not an integer" 2.IX Item "$x ** $y where $y is not an integer".IP "\fIbmod()\fR, \fIblog()\fR, \fIbmodinv()\fR and \fIbmodpow()\fR (partial)" 2.IX Item "bmod(), blog(), bmodinv() and bmodpow() (partial)".PD.SH "LICENSE".IX Header "LICENSE"This program is free software; you may redistribute it and/or modify it underthe same terms as Perl itself..SH "SEE ALSO".IX Header "SEE ALSO"Math::BigFloat and Math::Big as well as Math::BigInt::BitVect,Math::BigInt::Pari and Math::BigInt::GMP..PPSee <http://search.cpan.org/search?dist=bignum> for a way to useMath::BigRat..PPThe package at <http://search.cpan.org/search?dist=Math%3A%3ABigRat>may contain more documentation and examples as well as testcases..SH "AUTHORS".IX Header "AUTHORS"(C) by Tels <http://bloodgate.com/> 2001 \- 2007.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -