📄 math::bigfloat.3
字号:
Calculate the arcus tanges of \f(CW$y\fR divided by \f(CW$x\fR, modifying \f(CW$y\fR in place.See also \fIbatan()\fR..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(1);\& print $x\->batan(100), "\en";.Ve.PPCalculate the arcus tanges of \f(CW$x\fR, modifying \f(CW$x\fR in place. See also \fIbatan2()\fR..PPThis method was added in v1.87 of Math::BigInt (June 2007)..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 "Autocreating constants".IX Header "Autocreating constants"After \f(CW\*(C`use Math::BigFloat \*(Aq:constant\*(Aq\*(C'\fR all the floating point constantsin the given scope are converted to \f(CW\*(C`Math::BigFloat\*(C'\fR. This conversionhappens at compile time..PPIn particular.PP.Vb 1\& perl \-MMath::BigFloat=:constant \-e \*(Aqprint 2E\-100,"\en"\*(Aq.Ve.PPprints the value of \f(CW\*(C`2E\-100\*(C'\fR. Note that without conversion of constants the expression 2E\-100 will be calculated as normal floating point number..PPPlease note that ':constant' does not affect integer constants, nor binary nor hexadecimal constants. Use bignum or Math::BigInt to get this towork..Sh "Math library".IX Subsection "Math library"Math with the numbers is done (by default) by a module calledMath::BigInt::Calc. This is equivalent to saying:.PP.Vb 1\& use Math::BigFloat lib => \*(AqCalc\*(Aq;.Ve.PPYou can change this by using:.PP.Vb 1\& use Math::BigFloat lib => \*(AqGMP\*(Aq;.Ve.PPNote: The keyword 'lib' will warn when the requested library could not beloaded. To suppress the warning use 'try' instead:.PP.Vb 1\& use Math::BigFloat try => \*(AqGMP\*(Aq;.Ve.PPTo turn the warning into a \fIdie()\fR, use 'only' instead:.PP.Vb 1\& use Math::BigFloat only => \*(AqGMP\*(Aq;.Ve.PPThe following would first try to find Math::BigInt::Foo, thenMath::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:.PP.Vb 1\& use Math::BigFloat lib => \*(AqFoo,Math::BigInt::Bar\*(Aq;.Ve.PPSee the respective low-level library documentation for further details..PPPlease note that Math::BigFloat does \fBnot\fR use the denoted library itself,but it merely passes the lib argument to Math::BigInt. So, instead of the needto do:.PP.Vb 2\& use Math::BigInt lib => \*(AqGMP\*(Aq;\& use Math::BigFloat;.Ve.PPyou can roll it all into one line:.PP.Vb 1\& use Math::BigFloat lib => \*(AqGMP\*(Aq;.Ve.PPIt is also possible to just require Math::BigFloat:.PP.Vb 1\& require Math::BigFloat;.Ve.PPThis will load the necessary things (like BigInt) when they are needed, andautomatically..PPSee Math::BigInt for more details than you ever wanted to know about usinga different low-level library..Sh "Using Math::BigInt::Lite".IX Subsection "Using Math::BigInt::Lite"For backwards compatibility reasons it is still possible torequest a different storage class for use with Math::BigFloat:.PP.Vb 1\& use Math::BigFloat with => \*(AqMath::BigInt::Lite\*(Aq;.Ve.PPHowever, this request is ignored, as the current code now uses the low-levelmath libary for directly storing the number parts..SH "EXPORTS".IX Header "EXPORTS"\&\f(CW\*(C`Math::BigFloat\*(C'\fR exports nothing by default, but can export the \f(CW\*(C`bpi()\*(C'\fR method:.PP.Vb 1\& use Math::BigFloat qw/bpi/;\&\& print bpi(10), "\en";.Ve.SH "BUGS".IX Header "BUGS"Please see the file \s-1BUGS\s0 in the \s-1CPAN\s0 distribution Math::BigInt for known bugs..SH "CAVEATS".IX Header "CAVEATS"Do not try to be clever to insert some operations in between switchinglibraries:.PP.Vb 4\& require Math::BigFloat;\& my $matter = Math::BigFloat\->bone() + 4; # load BigInt and Calc\& Math::BigFloat\->import( lib => \*(AqPari\*(Aq ); # load Pari, too\& my $anti_matter = Math::BigFloat\->bone()+4; # now use Pari.Ve.PPThis will create objects with numbers stored in two different backend libraries,and \fB\s-1VERY\s0 \s-1BAD\s0 \s-1THINGS\s0\fR will happen when you use these together:.PP.Vb 1\& my $flash_and_bang = $matter + $anti_matter; # Don\*(Aqt do this!.Ve.IP "stringify, \fIbstr()\fR" 1.IX Item "stringify, bstr()"Both stringify and \fIbstr()\fR now drop the leading '+'. The old code would return\&'+1.23', the new returns '1.23'. See the documentation in Math::BigInt forreasoning and details..IP "bdiv" 1.IX Item "bdiv"The following will probably not print what you expect:.Sp.Vb 1\& print $c\->bdiv(123.456),"\en";.Ve.SpIt prints both quotient and reminder since print works in list context. Also,\&\fIbdiv()\fR will modify \f(CW$c\fR, so be careful. You probably want to use.Sp.Vb 2\& print $c / 123.456,"\en";\& print scalar $c\->bdiv(123.456),"\en"; # or if you want to modify $c.Ve.Spinstead..IP "brsft" 1.IX Item "brsft"The following will probably not print what you expect:.Sp.Vb 2\& my $c = Math::BigFloat\->new(\*(Aq3.14159\*(Aq);\& print $c\->brsft(3,10),"\en"; # prints 0.00314153.1415.Ve.SpIt prints both quotient and remainder, since print calls \f(CW\*(C`brsft()\*(C'\fR in listcontext. Also, \f(CW\*(C`$c\->brsft()\*(C'\fR will modify \f(CW$c\fR, so be careful.You probably want to use.Sp.Vb 3\& print scalar $c\->copy()\->brsft(3,10),"\en";\& # or if you really want to modify $c\& print scalar $c\->brsft(3,10),"\en";.Ve.Spinstead..IP "Modifying and =" 1.IX Item "Modifying and ="Beware of:.Sp.Vb 2\& $x = Math::BigFloat\->new(5);\& $y = $x;.Ve.SpIt will not do what you think, e.g. making a copy of \f(CW$x\fR. Instead it just makesa second reference to the \fBsame\fR object and stores it in \f(CW$y\fR. Thus anythingthat modifies \f(CW$x\fR will modify \f(CW$y\fR (except overloaded math operators), and viceversa. See Math::BigInt for details and how to avoid that..IP "bpow" 1.IX Item "bpow"\&\f(CW\*(C`bpow()\*(C'\fR now modifies the first argument, unlike the old code which leftit alone and only returned the result. This is to be consistent with\&\f(CW\*(C`badd()\*(C'\fR etc. The first will modify \f(CW$x\fR, the second one won't:.Sp.Vb 3\& print bpow($x,$i),"\en"; # modify $x\& print $x\->bpow($i),"\en"; # ditto\& print $x ** $i,"\en"; # leave $x alone.Ve.IP "\fIprecision()\fR vs. \fIaccuracy()\fR" 1.IX Item "precision() vs. accuracy()"A common pitfall is to use \fIprecision()\fR when you want to round a result toa certain number of digits:.Sp.Vb 1\& use Math::BigFloat;\&\& Math::BigFloat\->precision(4); # does not do what you think it does\& my $x = Math::BigFloat\->new(12345); # rounds $x to "12000"!\& print "$x\en"; # print "12000"\& my $y = Math::BigFloat\->new(3); # rounds $y to "0"!\& print "$y\en"; # print "0"\& $z = $x / $y; # 12000 / 0 => NaN!\& print "$z\en";\& print $z\->precision(),"\en"; # 4.Ve.SpReplacing precision with accuracy is probably not what you want, either:.Sp.Vb 1\& use Math::BigFloat;\&\& Math::BigFloat\->accuracy(4); # enables global rounding:\& my $x = Math::BigFloat\->new(123456); # rounded immediately to "12350"\& print "$x\en"; # print "123500"\& my $y = Math::BigFloat\->new(3); # rounded to "3\& print "$y\en"; # print "3"\& print $z = $x\->copy()\->bdiv($y),"\en"; # 41170\& print $z\->accuracy(),"\en"; # 4.Ve.SpWhat you want to use instead is:.Sp.Vb 1\& use Math::BigFloat;\&\& my $x = Math::BigFloat\->new(123456); # no rounding\& print "$x\en"; # print "123456"\& my $y = Math::BigFloat\->new(3); # no rounding\& print "$y\en"; # print "3"\& print $z = $x\->copy()\->bdiv($y,4),"\en"; # 41150\& print $z\->accuracy(),"\en"; # undef.Ve.SpIn addition to computing what you expected, the last example also does \fBnot\fR\&\*(L"taint\*(R" the result with an accuracy or precision setting, which wouldinfluence any further operation..SH "SEE ALSO".IX Header "SEE ALSO"Math::BigInt, Math::BigRat and Math::Big as well asMath::BigInt::BitVect, Math::BigInt::Pari and Math::BigInt::GMP..PPThe pragmas bignum, bigint and bigrat might also be of interestbecause they solve the autoupgrading/downgrading issue, at least partly..PPThe package at <http://search.cpan.org/~tels/Math\-BigInt> containsmore documentation including a full version history, testcases, emptysubclass files and benchmarks..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 "AUTHORS".IX Header "AUTHORS"Mark Biggar, overloaded interface by Ilya Zakharevich.Completely rewritten by Tels <http://bloodgate.com> in 2001 \- 2006, and stillat it in 2007.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -