Math::BigFloat - Arbitrary length float math package


  use Math::BigFloat;
  $f = Math::BigFloat->new($string);

  $f->fadd(NSTR) return NSTR            addition
  $f->fsub(NSTR) return NSTR            subtraction
  $f->fmul(NSTR) return NSTR            multiplication
  $f->fdiv(NSTR[,SCALE]) returns NSTR   division to SCALE places
  $f->fneg() return NSTR                negation
  $f->fabs() return NSTR                absolute value
  $f->fcmp(NSTR) return CODE            compare undef,<0,=0,>0
  $f->fround(SCALE) return NSTR         round to SCALE digits
  $f->ffround(SCALE) return NSTR        round at SCALEth place
  $f->fnorm() return (NSTR)             normalize
  $f->fsqrt([SCALE]) return NSTR        sqrt to SCALE places


All basic math operations are overloaded if you declare your big floats as

    $float = new Math::BigFloat "2.123123123123123123123123123123123";
number format

canonical strings have the form /[+-]\d+E[+-]\d+/ . Input values can have inbedded whitespace.

Error returns 'NaN'

An input parameter was ``Not a Number'' or divide by zero or sqrt of negative number.

Division is computed to

max($div_scale,length(dividend)+length(divisor)) digits by default. Also used for default sqrt scale.


The current version of this module is a preliminary version of the real thing that is currently (as of perl5.002) under development.


Mark Biggar


We are painfully aware that these documents may contain incorrect links and misformatted HTML. Such bugs lie in the automatic translation process that automatically created the hundreds and hundreds of separate documents that you find here. Please do not report link or formatting bugs, because we cannot fix per-document problems. The only bug reports that will help us are those that supply working patches to the installhtml or pod2html programs, or to the Pod::HTML module itself, for which I and the entire Perl community will shower you with thanks and praises.

If rather than formatting bugs, you encounter substantive content errors in these documents, such as mistakes in the explanations or code, please use the perlbug utility included with the Perl distribution.

--Tom Christiansen, Perl Documentation Compiler and Editor

Return to the Perl Documentation Index.
Return to the Perl Home Page.