📄 math::bigint.3
字号:
Compares \f(CW$x\fR with \f(CW$y\fR while ignoring their. Returns \-1, 0, 1 or undef..Sh "\fIsign()\fP".IX Subsection "sign()".Vb 1\& $x\->sign();.Ve.PPReturn the sign, of \f(CW$x\fR, meaning either \f(CW\*(C`+\*(C'\fR, \f(CW\*(C`\-\*(C'\fR, \f(CW\*(C`\-inf\*(C'\fR, \f(CW\*(C`+inf\*(C'\fR or NaN..PPIf you want \f(CW$x\fR to have a certain sign, use one of the following methods:.PP.Vb 5\& $x\->babs(); # \*(Aq+\*(Aq\& $x\->babs()\->bneg(); # \*(Aq\-\*(Aq\& $x\->bnan(); # \*(AqNaN\*(Aq\& $x\->binf(); # \*(Aq+inf\*(Aq\& $x\->binf(\*(Aq\-\*(Aq); # \*(Aq\-inf\*(Aq.Ve.Sh "\fIdigit()\fP".IX Subsection "digit()".Vb 1\& $x\->digit($n); # return the nth digit, counting from right.Ve.PPIf \f(CW$n\fR is negative, returns the digit counting from left..Sh "\fIbneg()\fP".IX Subsection "bneg()".Vb 1\& $x\->bneg();.Ve.PPNegate the number, e.g. change the sign between '+' and '\-', or between '+inf'and '\-inf', respectively. Does nothing for NaN or zero..Sh "\fIbabs()\fP".IX Subsection "babs()".Vb 1\& $x\->babs();.Ve.PPSet the number to its absolute value, e.g. change the sign from '\-' to '+'and from '\-inf' to '+inf', respectively. Does nothing for NaN or positivenumbers..Sh "\fIbnorm()\fP".IX Subsection "bnorm()".Vb 1\& $x\->bnorm(); # normalize (no\-op).Ve.Sh "\fIbnot()\fP".IX Subsection "bnot()".Vb 1\& $x\->bnot();.Ve.PPTwo's complement (bitwise not). This is equivalent to.PP.Vb 1\& $x\->binc()\->bneg();.Ve.PPbut faster..Sh "\fIbinc()\fP".IX Subsection "binc()".Vb 1\& $x\->binc(); # increment x by 1.Ve.Sh "\fIbdec()\fP".IX Subsection "bdec()".Vb 1\& $x\->bdec(); # decrement x by 1.Ve.Sh "\fIbadd()\fP".IX Subsection "badd()".Vb 1\& $x\->badd($y); # addition (add $y to $x).Ve.Sh "\fIbsub()\fP".IX Subsection "bsub()".Vb 1\& $x\->bsub($y); # subtraction (subtract $y from $x).Ve.Sh "\fIbmul()\fP".IX Subsection "bmul()".Vb 1\& $x\->bmul($y); # multiplication (multiply $x by $y).Ve.Sh "\fIbmuladd()\fP".IX Subsection "bmuladd()".Vb 1\& $x\->bmuladd($y,$z);.Ve.PPMultiply \f(CW$x\fR by \f(CW$y\fR, and then add \f(CW$z\fR to the result,.PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIbdiv()\fP".IX Subsection "bdiv()".Vb 2\& $x\->bdiv($y); # divide, set $x to quotient\& # return (quo,rem) or quo if scalar.Ve.Sh "\fIbmod()\fP".IX Subsection "bmod()".Vb 1\& $x\->bmod($y); # modulus (x % y).Ve.Sh "\fIbmodinv()\fP".IX Subsection "bmodinv()".Vb 1\& num\->bmodinv($mod); # modular inverse.Ve.PPReturns the inverse of \f(CW$num\fR in the given modulus \f(CW$mod\fR. '\f(CW\*(C`NaN\*(C'\fR' isreturned unless \f(CW$num\fR is relatively prime to \f(CW$mod\fR, i.e. unless\&\f(CW\*(C`bgcd($num, $mod)==1\*(C'\fR..Sh "\fIbmodpow()\fP".IX Subsection "bmodpow()".Vb 2\& $num\->bmodpow($exp,$mod); # modular exponentation\& # ($num**$exp % $mod).Ve.PPReturns the value of \f(CW$num\fR taken to the power \f(CW$exp\fR in the modulus\&\f(CW$mod\fR using binary exponentation. \f(CW\*(C`bmodpow\*(C'\fR is far superior towriting.PP.Vb 1\& $num ** $exp % $mod.Ve.PPbecause it is much faster \- it reduces internal variables intothe modulus whenever possible, so it operates on smaller numbers..PP\&\f(CW\*(C`bmodpow\*(C'\fR also supports negative exponents..PP.Vb 1\& bmodpow($num, \-1, $mod).Ve.PPis exactly equivalent to.PP.Vb 1\& bmodinv($num, $mod).Ve.Sh "\fIbpow()\fP".IX Subsection "bpow()".Vb 1\& $x\->bpow($y); # power of arguments (x ** y).Ve.Sh "\fIblog()\fP".IX Subsection "blog()".Vb 1\& $x\->blog($base, $accuracy); # logarithm of x to the base $base.Ve.PPIf \f(CW$base\fR is not defined, Euler's number (e) is used:.PP.Vb 1\& print $x\->blog(undef, 100); # log(x) to 100 digits.Ve.Sh "\fIbexp()\fP".IX Subsection "bexp()".Vb 1\& $x\->bexp($accuracy); # calculate e ** X.Ve.PPCalculates the expression \f(CW\*(C`e ** $x\*(C'\fR where \f(CW\*(C`e\*(C'\fR is Euler's number..PPThis method was added in v1.82 of Math::BigInt (April 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 v1.84 of Math::BigInt (April 2007)..Sh "\fIbpi()\fP".IX Subsection "bpi()".Vb 1\& print Math::BigInt\->bpi(100), "\en"; # 3.Ve.PPReturns \s-1PI\s0 truncated to an integer, with the argument being ignored. This meansunder BigInt this always returns \f(CW3\fR..PPIf upgrading is in effect, returns \s-1PI\s0, rounded to N digits with thecurrent rounding mode:.PP.Vb 4\& use Math::BigFloat;\& use Math::BigInt upgrade => Math::BigFloat;\& print Math::BigInt\->bpi(3), "\en"; # 3.14\& print Math::BigInt\->bpi(100), "\en"; # 3.1415.....Ve.PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIbcos()\fP".IX Subsection "bcos()".Vb 2\& my $x = Math::BigInt\->new(1);\& print $x\->bcos(100), "\en";.Ve.PPCalculate the cosinus of \f(CW$x\fR, modifying \f(CW$x\fR in place..PPIn BigInt, unless upgrading is in effect, the result is truncated to aninteger..PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIbsin()\fP".IX Subsection "bsin()".Vb 2\& my $x = Math::BigInt\->new(1);\& print $x\->bsin(100), "\en";.Ve.PPCalculate the sinus of \f(CW$x\fR, modifying \f(CW$x\fR in place..PPIn BigInt, unless upgrading is in effect, the result is truncated to aninteger..PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIbatan2()\fP".IX Subsection "batan2()".Vb 3\& my $x = Math::BigInt\->new(1);\& my $y = Math::BigInt\->new(1);\& print $y\->batan2($x), "\en";.Ve.PPCalculate the arcus tangens of \f(CW$y\fR divided by \f(CW$x\fR, modifying \f(CW$y\fR in place..PPIn BigInt, unless upgrading is in effect, the result is truncated to aninteger..PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIbatan()\fP".IX Subsection "batan()".Vb 2\& my $x = Math::BigFloat\->new(0.5);\& print $x\->batan(100), "\en";.Ve.PPCalculate the arcus tangens of \f(CW$x\fR, modifying \f(CW$x\fR in place..PPIn BigInt, unless upgrading is in effect, the result is truncated to aninteger..PPThis method was added in v1.87 of Math::BigInt (June 2007)..Sh "\fIblsft()\fP".IX Subsection "blsft()".Vb 2\& $x\->blsft($y); # left shift in base 2\& $x\->blsft($y,$n); # left shift, in base $n (like 10).Ve.Sh "\fIbrsft()\fP".IX Subsection "brsft()".Vb 2\& $x\->brsft($y); # right shift in base 2\& $x\->brsft($y,$n); # right shift, in base $n (like 10).Ve.Sh "\fIband()\fP".IX Subsection "band()".Vb 1\& $x\->band($y); # bitwise and.Ve.Sh "\fIbior()\fP".IX Subsection "bior()".Vb 1\& $x\->bior($y); # bitwise inclusive or.Ve.Sh "\fIbxor()\fP".IX Subsection "bxor()".Vb 1\& $x\->bxor($y); # bitwise exclusive or.Ve.Sh "\fIbnot()\fP".IX Subsection "bnot()".Vb 1\& $x\->bnot(); # bitwise not (two\*(Aqs complement).Ve.Sh "\fIbsqrt()\fP".IX Subsection "bsqrt()".Vb 1\& $x\->bsqrt(); # calculate square\-root.Ve.Sh "\fIbroot()\fP".IX Subsection "broot()".Vb 1\& $x\->broot($N);.Ve.PPCalculates the N'th root of \f(CW$x\fR..Sh "\fIbfac()\fP".IX Subsection "bfac()".Vb 1\& $x\->bfac(); # factorial of $x (1*2*3*4*..$x).Ve.Sh "\fIround()\fP".IX Subsection "round()".Vb 1\& $x\->round($A,$P,$round_mode);.Ve.PPRound \f(CW$x\fR to accuracy \f(CW$A\fR or precision \f(CW$P\fR using the round mode\&\f(CW$round_mode\fR..Sh "\fIbround()\fP".IX Subsection "bround()".Vb 1\& $x\->bround($N); # accuracy: preserve $N digits.Ve.Sh "\fIbfround()\fP".IX Subsection "bfround()".Vb 1\& $x\->bfround($N);.Ve.PPIf N is > 0, rounds to the Nth digit from the left. If N < 0, rounds tothe Nth digit after the dot. Since BigInts are integers, the case N < 0is a no-op for them..PPExamples:.PP.Vb 6\& Input N Result\& ===================================================\& 123456.123456 3 123500\& 123456.123456 2 123450\& 123456.123456 \-2 123456.12\& 123456.123456 \-3 123456.123.Ve.Sh "\fIbfloor()\fP".IX Subsection "bfloor()".Vb 1\& $x\->bfloor();.Ve.PPSet \f(CW$x\fR to the integer less or equal than \f(CW$x\fR. This is a no-op in BigInt, butdoes change \f(CW$x\fR in BigFloat..Sh "\fIbceil()\fP".IX Subsection "bceil()"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -