.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.el \{\
.    de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Math::BigFloat 3pm"
.TH Math::BigFloat 3pm "2009-02-12" "perl v5.10.1" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Math::BigFloat \- Arbitrary size floating point math package
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&  use Math::BigFloat;
\&
\&  # Number creation
\&  my $x = Math::BigFloat\->new($str);    # defaults to 0
\&  my $y = $x\->copy();                   # make a true copy
\&  my $nan  = Math::BigFloat\->bnan();    # create a NotANumber
\&  my $zero = Math::BigFloat\->bzero();   # create a +0
\&  my $inf = Math::BigFloat\->binf();     # create a +inf
\&  my $inf = Math::BigFloat\->binf(\*(Aq\-\*(Aq);  # create a \-inf
\&  my $one = Math::BigFloat\->bone();     # create a +1
\&  my $mone = Math::BigFloat\->bone(\*(Aq\-\*(Aq); # create a \-1
\&
\&  my $pi = Math::BigFloat\->bpi(100);    # PI to 100 digits
\&
\&  # the following examples compute their result to 100 digits accuracy:
\&  my $cos  = Math::BigFloat\->new(1)\->bcos(100);         # cosinus(1)
\&  my $sin  = Math::BigFloat\->new(1)\->bsin(100);         # sinus(1)
\&  my $atan = Math::BigFloat\->new(1)\->batan(100);        # arcus tangens(1)
\&
\&  my $atan2 = Math::BigFloat\->new(  1 )\->batan2( 1 ,100); # batan(1)
\&  my $atan2 = Math::BigFloat\->new(  1 )\->batan2( 8 ,100); # batan(1/8)
\&  my $atan2 = Math::BigFloat\->new( \-2 )\->batan2( 1 ,100); # batan(\-2)
\&
\&  # Testing
\&  $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(\*(Aq\-\*(Aq);              # true if arg is \-1
\&  $x\->is_odd();                 # true if odd, false for even
\&  $x\->is_even();                # true if even, false for odd
\&  $x\->is_pos();                 # true if >= 0
\&  $x\->is_neg();                 # true if <  0
\&  $x\->is_inf(sign);             # true if +inf, or \-inf (default is \*(Aq+\*(Aq)
\&
\&  $x\->bcmp($y);                 # compare numbers (undef,<0,=0,>0)
\&  $x\->bacmp($y);                # compare absolutely (undef,<0,=0,>0)
\&  $x\->sign();                   # return the sign, either +,\- or NaN
\&  $x\->digit($n);                # return the nth digit, counting from right
\&  $x\->digit(\-$n);               # return the nth digit, counting from left 
\&
\&  # The following all modify their first argument. If you want to preserve
\&  # $x, use $z = $x\->copy()\->bXXX($y); See under L<CAVEATS> for why this is
\&  # necessary when mixing $a = $b assignments with non\-overloaded math.
\& 
\&  # set 
\&  $x\->bzero();                  # set $i to 0
\&  $x\->bnan();                   # set $i to NaN
\&  $x\->bone();                   # set $x to +1
\&  $x\->bone(\*(Aq\-\*(Aq);                # set $x to \-1
\&  $x\->binf();                   # set $x to inf
\&  $x\->binf(\*(Aq\-\*(Aq);                # set $x to \-inf
\&
\&  $x\->bneg();                   # negation
\&  $x\->babs();                   # absolute value
\&  $x\->bnorm();                  # normalize (no\-op)
\&  $x\->bnot();                   # two\*(Aqs complement (bit wise not)
\&  $x\->binc();                   # increment x by 1
\&  $x\->bdec();                   # decrement x by 1
\&  
\&  $x\->badd($y);                 # addition (add $y to $x)
\&  $x\->bsub($y);                 # subtraction (subtract $y from $x)
\&  $x\->bmul($y);                 # multiplication (multiply $x by $y)
\&  $x\->bdiv($y);                 # divide, set $x to quotient
\&                                # return (quo,rem) or quo if scalar
\&
\&  $x\->bmod($y);                 # modulus ($x % $y)
\&  $x\->bpow($y);                 # power of arguments ($x ** $y)
\&  $x\->bmodpow($exp,$mod);       # modular exponentation (($num**$exp) % $mod))
\&  $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 scalar context
\&  
\&  $x\->blog();                   # logarithm of $x to base e (Euler\*(Aqs number)
\&  $x\->blog($base);              # logarithm of $x to base $base (f.i. 2)
\&  $x\->bexp();                   # calculate e ** $x where e is Euler\*(Aqs number
\&  
\&  $x\->band($y);                 # bit\-wise and
\&  $x\->bior($y);                 # bit\-wise inclusive or
\&  $x\->bxor($y);                 # bit\-wise exclusive or
\&  $x\->bnot();                   # bit\-wise not (two\*(Aqs complement)
\& 
\&  $x\->bsqrt();                  # calculate square\-root
\&  $x\->broot($y);                # $y\*(Aqth root of $x (e.g. $y == 3 => cubic root)
\&  $x\->bfac();                   # factorial of $x (1*2*3*4*..$x)
\& 
\&  $x\->bround($N);               # accuracy: preserve $N digits
\&  $x\->bfround($N);              # precision: round to the $Nth digit
\&
\&  $x\->bfloor();                 # return integer less or equal than $x
\&  $x\->bceil();                  # return integer greater or equal than $x
\&
\&  # The following do not modify their arguments:
\&
\&  bgcd(@values);                # greatest common divisor
\&  blcm(@values);                # lowest common multiplicator
\&  
\&  $x\->bstr();                   # return string
\&  $x\->bsstr();                  # return string in scientific notation
\&
\&  $x\->as_int();                 # return $x as BigInt 
\&  $x\->exponent();               # return exponent as BigInt
\&  $x\->mantissa();               # return mantissa as BigInt
\&  $x\->parts();                  # return (mantissa,exponent) as BigInt
\&
\&  $x\->length();                 # number of digits (w/o sign and \*(Aq.\*(Aq)
\&  ($l,$f) = $x\->length();       # number of digits, and length of fraction      
\&
\&  $x\->precision();              # return P of $x (or global, if P of $x undef)
\&  $x\->precision($n);            # set P of $x to $n
\&  $x\->accuracy();               # return A of $x (or global, if A of $x undef)
\&  $x\->accuracy($n);             # set A $x to $n
\&
\&  # these get/set the appropriate global value for all BigFloat objects
\&  Math::BigFloat\->precision();  # Precision
\&  Math::BigFloat\->accuracy();   # Accuracy
\&  Math::BigFloat\->round_mode(); # rounding mode
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
All operators (including basic math operations) are overloaded if you
declare your big floating point numbers as
.PP
.Vb 1
\&  $i = new Math::BigFloat \*(Aq12_3.456_789_123_456_789E\-2\*(Aq;
.Ve
.PP
Operations with overloaded operators preserve the arguments, which is
exactly what you expect.
.SS "Canonical notation"
.IX Subsection "Canonical notation"
Input to these routines are either BigFloat objects, or strings of the
following four forms:
.IP "\(bu" 2
\&\f(CW\*(C`/^[+\-]\ed+$/\*(C'\fR
.IP "\(bu" 2
\&\f(CW\*(C`/^[+\-]\ed+\e.\ed*$/\*(C'\fR
.IP "\(bu" 2
\&\f(CW\*(C`/^[+\-]\ed+E[+\-]?\ed+$/\*(C'\fR
.IP "\(bu" 2
\&\f(CW\*(C`/^[+\-]\ed*\e.\ed+E[+\-]?\ed+$/\*(C'\fR
.PP
all with optional leading and trailing zeros and/or spaces. Additionally,
numbers are allowed to have an underscore between any two digits.
.PP
Empty strings as well as other illegal numbers results in 'NaN'.
.PP
\&\fIbnorm()\fR on a BigFloat object is now effectively a no-op, since the numbers 
are always stored in normalized form. On a string, it creates a BigFloat 
object.
.SS "Output"
.IX Subsection "Output"
Output values are BigFloat objects (normalized), except for \fIbstr()\fR and \fIbsstr()\fR.
.PP
The string output will always have leading and trailing zeros stripped and drop
a plus sign. \f(CW\*(C`bstr()\*(C'\fR will give you always the form with a decimal point,
while \f(CW\*(C`bsstr()\*(C'\fR (s for scientific) gives you the scientific notation.
.PP
.Vb 6
\&        Input                   bstr()          bsstr()
\&        \*(Aq\-0\*(Aq                    \*(Aq0\*(Aq             \*(Aq0E1\*(Aq
\&        \*(Aq  \-123 123 123\*(Aq        \*(Aq\-123123123\*(Aq    \*(Aq\-123123123E0\*(Aq
\&        \*(Aq00.0123\*(Aq               \*(Aq0.0123\*(Aq        \*(Aq123E\-4\*(Aq
\&        \*(Aq123.45E\-2\*(Aq             \*(Aq1.2345\*(Aq        \*(Aq12345E\-4\*(Aq
\&        \*(Aq10E+3\*(Aq                 \*(Aq10000\*(Aq         \*(Aq1E4\*(Aq
.Ve
.PP
Some routines (\f(CW\*(C`is_odd()\*(C'\fR, \f(CW\*(C`is_even()\*(C'\fR, \f(CW\*(C`is_zero()\*(C'\fR, \f(CW\*(C`is_one()\*(C'\fR,
\&\f(CW\*(C`is_nan()\*(C'\fR) return true or false, while others (\f(CW\*(C`bcmp()\*(C'\fR, \f(CW\*(C`bacmp()\*(C'\fR)
return either undef, <0, 0 or >0 and are suited for sort.
.PP
Actual math is done by using the class defined with \f(CW\*(C`with =\*(C'\fR Class;> (which
defaults to BigInts) to represent the mantissa and exponent.
.PP
The sign \f(CW\*(C`/^[+\-]$/\*(C'\fR is stored separately. The string 'NaN' is used to 
represent the result when input arguments are not numbers, as well as 
the result of dividing by zero.
.ie n .SS """mantissa()"", ""exponent()"" and ""parts()"""
.el .SS "\f(CWmantissa()\fP, \f(CWexponent()\fP and \f(CWparts()\fP"
.IX Subsection "mantissa(), exponent() and parts()"
\&\f(CW\*(C`mantissa()\*(C'\fR and \f(CW\*(C`exponent()\*(C'\fR return the said parts of the BigFloat 
as BigInts such that:
.PP
.Vb 4
\&        $m = $x\->mantissa();
\&        $e = $x\->exponent();
\&        $y = $m * ( 10 ** $e );
\&        print "ok\en" if $x == $y;
.Ve
.PP
\&\f(CW\*(C`($m,$e) = $x\->parts();\*(C'\fR is just a shortcut giving you both of them.
.PP
A zero is represented and returned as \f(CW0E1\fR, \fBnot\fR \f(CW0E0\fR (after Knuth).
.PP
Currently the mantissa is reduced as much as possible, favouring higher
exponents over lower ones (e.g. returning 1e7 instead of 10e6 or 10000000e0).
This might change in the future, so do not depend on it.
.SS "Accuracy vs. Precision"
.IX Subsection "Accuracy vs. Precision"
See also: Rounding.
.PP
Math::BigFloat supports both precision (rounding to a certain place before or
after the dot) and accuracy (rounding to a certain number of digits). For a
full documentation, examples and tips on these topics please see the large
section about rounding in Math::BigInt.
.PP
Since things like \f(CWsqrt(2)\fR or \f(CW\*(C`1 / 3\*(C'\fR must presented with a limited
accuracy lest a operation consumes all resources, each operation produces
no more than the requested number of digits.
.PP
If there is no gloabl precision or accuracy set, \fBand\fR the operation in
question was not called with a requested precision or accuracy, \fBand\fR the
input \f(CW$x\fR has no accuracy or precision set, then a fallback parameter will
be used. For historical reasons, it is called \f(CW\*(C`div_scale\*(C'\fR and can be accessed
via:
.PP
.Vb 2
\&        $d = Math::BigFloat\->div_scale();               # query
\&        Math::BigFloat\->div_scale($n);                  # set to $n digits
.Ve
.PP
The default value for \f(CW\*(C`div_scale\*(C'\fR is 40.
.PP
In case the result of one operation has more digits than specified,
it is rounded. The rounding mode taken is either the default mode, or the one
supplied to the operation after the \fIscale\fR:
.PP
.Vb 7
\&        $x = Math::BigFloat\->new(2);
\&        Math::BigFloat\->accuracy(5);            # 5 digits max
\&        $y = $x\->copy()\->bdiv(3);               # will give 0.66667
\&        $y = $x\->copy()\->bdiv(3,6);             # will give 0.666667
\&        $y = $x\->copy()\->bdiv(3,6,undef,\*(Aqodd\*(Aq); # will give 0.666667
\&        Math::BigFloat\->round_mode(\*(Aqzero\*(Aq);
\&        $y = $x\->copy()\->bdiv(3,6);             # will also give 0.666667
.Ve
.PP
Note that \f(CW\*(C`Math::BigFloat\->accuracy()\*(C'\fR and \f(CW\*(C`Math::BigFloat\->precision()\*(C'\fR
set the global variables, and thus \fBany\fR newly created number will be subject
to the global rounding \fBimmediately\fR. This means that in the examples above, the
\&\f(CW3\fR as argument to \f(CW\*(C`bdiv()\*(C'\fR will also get an accuracy of \fB5\fR.
.PP
It is less confusing to either calculate the result fully, and afterwards
round it explicitly, or use the additional parameters to the math
functions like so:
.PP
.Vb 4
\&        use Math::BigFloat;     
\&        $x = Math::BigFloat\->new(2);
\&        $y = $x\->copy()\->bdiv(3);
\&        print $y\->bround(5),"\en";               # will give 0.66667
\&
\&        or
\&
\&        use Math::BigFloat;     
\&        $x = Math::BigFloat\->new(2);
\&        $y = $x\->copy()\->bdiv(3,5);             # will give 0.66667
\&        print "$y\en";
.Ve
.SS "Rounding"
.IX Subsection "Rounding"
.IP "ffround ( +$scale )" 2
.IX Item "ffround ( +$scale )"
Rounds to the \f(CW$scale\fR'th place left from the '.', counting from the dot.
The first digit is numbered 1.
.IP "ffround ( \-$scale )" 2
.IX Item "ffround ( -$scale )"
Rounds to the \f(CW$scale\fR'th place right from the '.', counting from the dot.
.IP "ffround ( 0 )" 2
.IX Item "ffround ( 0 )"
Rounds to an integer.
.IP "fround  ( +$scale )" 2
.IX Item "fround  ( +$scale )"
Preserves accuracy to \f(CW$scale\fR digits from the left (aka significant digits)
and pads the rest with zeros. If the number is between 1 and \-1, the
significant digits count from the first non-zero after the '.'
.IP "fround  ( \-$scale ) and fround ( 0 )" 2
.IX Item "fround  ( -$scale ) and fround ( 0 )"
These are effectively no-ops.
.PP
All rounding functions take as a second parameter a rounding mode from one of
the following: 'even', 'odd', '+inf', '\-inf', 'zero', 'trunc' or 'common'.
.PP
The default rounding mode is 'even'. By using
\&\f(CW\*(C`Math::BigFloat\->round_mode($round_mode);\*(C'\fR you can get and set the default
mode for subsequent rounding. The usage of \f(CW\*(C`$Math::BigFloat::$round_mode\*(C'\fR is
no longer supported.
The second parameter to the round functions then overrides the default
temporarily.
.PP
The \f(CW\*(C`as_number()\*(C'\fR function returns a BigInt from a Math::BigFloat. It uses
\&'trunc' as rounding mode to make it equivalent to:
.PP
.Vb 2
\&        $x = 2.5;
\&        $y = int($x) + 2;
.Ve
.PP
You can override this by passing the desired rounding mode as parameter to
\&\f(CW\*(C`as_number()\*(C'\fR:
.PP
.Vb 2
\&        $x = Math::BigFloat\->new(2.5);
\&        $y = $x\->as_number(\*(Aqodd\*(Aq);      # $y = 3
.Ve
.SH "METHODS"
.IX Header "METHODS"
Math::BigFloat supports all methods that Math::BigInt supports, except it
calculates non-integer results when possible. Please see Math::BigInt
for a full description of each method. Below are just the most important
differences:
.SS "accuracy"
.IX Subsection "accuracy"
.Vb 3
\&        $x\->accuracy(5);                # local for $x
\&        CLASS\->accuracy(5);             # global for all members of CLASS
\&                                        # Note: This also applies to new()!
\&
\&        $A = $x\->accuracy();            # read out accuracy that affects $x
\&        $A = CLASS\->accuracy();         # read out global accuracy
.Ve
.PP
Set or get the global or local accuracy, aka how many significant digits the
results have. If you set a global accuracy, then this also applies to \fInew()\fR!
.PP
Warning! The accuracy \fIsticks\fR, e.g. once you created a number under the
influence of \f(CW\*(C`CLASS\->accuracy($A)\*(C'\fR, all results from math operations with
that number will also be rounded.
.PP
In most cases, you should probably round the results explicitly using one of
\&\fIround()\fR, \fIbround()\fR or \fIbfround()\fR or by passing the desired accuracy
to the math operation as additional parameter:
.PP
.Vb 4
\&        my $x = Math::BigInt\->new(30000);
\&        my $y = Math::BigInt\->new(7);
\&        print scalar $x\->copy()\->bdiv($y, 2);           # print 4300
\&        print scalar $x\->copy()\->bdiv($y)\->bround(2);   # print 4300
.Ve
.SS "\fIprecision()\fP"
.IX Subsection "precision()"
.Vb 2
\&        $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
\&
\&        $P = CLASS\->precision();        # read out global precision
\&        $P = $x\->precision();           # read out precision that affects $x
.Ve
.PP
Note: You probably want to use \fIaccuracy()\fR instead. With accuracy you
set the number of digits each result should have, with precision you
set the place where to round!
.SS "\fIbexp()\fP"
.IX Subsection "bexp()"
.Vb 1
\&        $x\->bexp($accuracy);            # calculate e ** X
.Ve
.PP
Calculates the expression \f(CW\*(C`e ** $x\*(C'\fR where \f(CW\*(C`e\*(C'\fR is Euler's number.
.PP
This method was added in v1.82 of Math::BigInt (April 2007).
.SS "\fIbnok()\fP"
.IX Subsection "bnok()"
.Vb 1
\&        $x\->bnok($y);              # x over y (binomial coefficient n over k)
.Ve
.PP
Calculates 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
.PP
This method was added in v1.84 of Math::BigInt (April 2007).
.SS "\fIbpi()\fP"
.IX Subsection "bpi()"
.Vb 1
\&        print Math::BigFloat\->bpi(100), "\en";
.Ve
.PP
Calculate \s-1PI\s0 to N digits (including the 3 before the dot). The result is
rounded according to the current rounding mode, which defaults to \*(L"even\*(R".
.PP
This method was added in v1.87 of Math::BigInt (June 2007).
.SS "\fIbcos()\fP"
.IX Subsection "bcos()"
.Vb 2
\&        my $x = Math::BigFloat\->new(1);
\&        print $x\->bcos(100), "\en";
.Ve
.PP
Calculate the cosinus of \f(CW$x\fR, modifying \f(CW$x\fR in place.
.PP
This method was added in v1.87 of Math::BigInt (June 2007).
.SS "\fIbsin()\fP"
.IX Subsection "bsin()"
.Vb 2
\&        my $x = Math::BigFloat\->new(1);
\&        print $x\->bsin(100), "\en";
.Ve
.PP
Calculate the sinus of \f(CW$x\fR, modifying \f(CW$x\fR in place.
.PP
This method was added in v1.87 of Math::BigInt (June 2007).
.SS "\fIbatan2()\fP"
.IX Subsection "batan2()"
.Vb 3
\&        my $y = Math::BigFloat\->new(2);
\&        my $x = Math::BigFloat\->new(3);
\&        print $y\->batan2($x), "\en";
.Ve
.PP
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.
.PP
This method was added in v1.87 of Math::BigInt (June 2007).
.SS "\fIbatan()\fP"
.IX Subsection "batan()"
.Vb 2
\&        my $x = Math::BigFloat\->new(1);
\&        print $x\->batan(100), "\en";
.Ve
.PP
Calculate the arcus tanges of \f(CW$x\fR, modifying \f(CW$x\fR in place. See also \fIbatan2()\fR.
.PP
This method was added in v1.87 of Math::BigInt (June 2007).
.SS "\fIbmuladd()\fP"
.IX Subsection "bmuladd()"
.Vb 1
\&        $x\->bmuladd($y,$z);
.Ve
.PP
Multiply \f(CW$x\fR by \f(CW$y\fR, and then add \f(CW$z\fR to the result.
.PP
This 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 constants
in the given scope are converted to \f(CW\*(C`Math::BigFloat\*(C'\fR. This conversion
happens at compile time.
.PP
In particular
.PP
.Vb 1
\&  perl \-MMath::BigFloat=:constant \-e \*(Aqprint 2E\-100,"\en"\*(Aq
.Ve
.PP
prints 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.
.PP
Please note that ':constant' does not affect integer constants, nor binary 
nor hexadecimal constants. Use bignum or Math::BigInt to get this to
work.
.SS "Math library"
.IX Subsection "Math library"
Math with the numbers is done (by default) by a module called
Math::BigInt::Calc. This is equivalent to saying:
.PP
.Vb 1
\&        use Math::BigFloat lib => \*(AqCalc\*(Aq;
.Ve
.PP
You can change this by using:
.PP
.Vb 1
\&        use Math::BigFloat lib => \*(AqGMP\*(Aq;
.Ve
.PP
\&\fBNote\fR: General purpose packages should not be explicit about the library
to use; let the script author decide which is best.
.PP
Note: The keyword 'lib' will warn when the requested library could not be
loaded. To suppress the warning use 'try' instead:
.PP
.Vb 1
\&        use Math::BigFloat try => \*(AqGMP\*(Aq;
.Ve
.PP
If your script works with huge numbers and Calc is too slow for them,
you can also for the loading of one of these libraries and if none
of them can be used, the code will die:
.PP
.Vb 1
\&        use Math::BigFloat only => \*(AqGMP,Pari\*(Aq;
.Ve
.PP
The following would first try to find Math::BigInt::Foo, then
Math::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
.PP
See the respective low-level library documentation for further details.
.PP
Please 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 need
to do:
.PP
.Vb 2
\&        use Math::BigInt lib => \*(AqGMP\*(Aq;
\&        use Math::BigFloat;
.Ve
.PP
you can roll it all into one line:
.PP
.Vb 1
\&        use Math::BigFloat lib => \*(AqGMP\*(Aq;
.Ve
.PP
It is also possible to just require Math::BigFloat:
.PP
.Vb 1
\&        require Math::BigFloat;
.Ve
.PP
This will load the necessary things (like BigInt) when they are needed, and
automatically.
.PP
See Math::BigInt for more details than you ever wanted to know about using
a different low-level library.
.SS "Using Math::BigInt::Lite"
.IX Subsection "Using Math::BigInt::Lite"
For backwards compatibility reasons it is still possible to
request a different storage class for use with Math::BigFloat:
.PP
.Vb 1
\&        use Math::BigFloat with => \*(AqMath::BigInt::Lite\*(Aq;
.Ve
.PP
However, this request is ignored, as the current code now uses the low-level
math 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 switching
libraries:
.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
.PP
This 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 for
reasoning 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
.Sp
It 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
.Sp
instead.
.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
.Sp
It prints both quotient and remainder, since print calls \f(CW\*(C`brsft()\*(C'\fR in list
context. 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
.Sp
instead.
.IP "Modifying and =" 1
.IX Item "Modifying and ="
Beware of:
.Sp
.Vb 2
\&        $x = Math::BigFloat\->new(5);
\&        $y = $x;
.Ve
.Sp
It will not do what you think, e.g. making a copy of \f(CW$x\fR. Instead it just makes
a second reference to the \fBsame\fR object and stores it in \f(CW$y\fR. Thus anything
that modifies \f(CW$x\fR will modify \f(CW$y\fR (except overloaded math operators), and vice
versa. 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 left
it 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 to
a 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
.Sp
Replacing 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
.Sp
What 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
.Sp
In 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 would
influence any further operation.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Math::BigInt, Math::BigRat and Math::Big as well as
Math::BigInt::BitVect, Math::BigInt::Pari and  Math::BigInt::GMP.
.PP
The pragmas bignum, bigint and bigrat might also be of interest
because they solve the autoupgrading/downgrading issue, at least partly.
.PP
The package at <http://search.cpan.org/~tels/Math\-BigInt> contains
more documentation including a full version history, testcases, empty
subclass files and benchmarks.
.SH "LICENSE"
.IX Header "LICENSE"
This program is free software; you may redistribute it and/or modify it under
the 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 still
at it in 2007.
