English     Español
[Main Index] : Programming : Languages : Perl : CPAN Modules : Data Type Utilities : Math : Math::BigInt
 Math::BigInt::Lite CPAN (Perl) Module 

Search

 

Documents

Math::BigInt::Lite - What BigInts are before they become big (Displayed)
README 

Math::BigInt::Lite - What BigInts are before they become big


NAME

Math::BigInt::Lite - What BigInts are before they become big


SYNOPSIS

  use Math::BigInt::Lite;
  $x = Math::BigInt::Lite->new(1);
  print $x->bstr(),"\n";                        # 1
  $x = Math::BigInt::Lite->new('1e1234');
  print $x->bsstr(),"\n";                       # 1e1234 (silently upgrades to
                                                # Math::BigInt)


DESCRIPTION

Math::BigInt is not very good suited to work with small (read: typical less than 10 digits) numbers, since it has a quite high per-operation overhead and is thus too slow.

But for some simple applications, you don't need rounding, infinity nor NaN handling, and yet want fast speed for small numbers without the risk of overflowing.

This is were Math::BigInt::Lite comes into play.

Math::BigInt::Lite objects should behave in every way like Math::BigInt objects, that is apart from the different label, you should not be able to tell the difference. Since Math::BigInt::Lite is designed with speed in mind, there are certain limitations build-in. In praxis, however, you will not feel them, because everytime something gets to big to pass as Lite (literally), it will upgrade the objects and operation in question to Math::BigInt.

Math library

Math with the numbers is done (by default) by a module called Math::BigInt::Calc. This is equivalent to saying:

        use Math::BigInt::Lite lib => 'Calc';

You can change this by using:

        use Math::BigInt::Lite lib => 'BitVect';

The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc:

        use Math::BigInt::Lite lib => 'Foo,Math::BigInt::Bar';

Calc.pm uses as internal format an array of elements of some decimal base (usually 1e7, but this might be differen for some systems) with the least significant digit first, while BitVect.pm uses a bit vector of base 2, most significant bit first. Other modules might use even different means of representing the numbers. See the respective module documentation for further details.

Please note that Math::BigInt::Lite does not use the denoted library itself, but it merely passes the lib argument to Math::BigInt. So, instead of the need to do:

        use Math::BigInt lib => 'GMP';
        use Math::BigInt::Lite;

you can roll it all into one line:

        use Math::BigInt::Lite lib => 'GMP';

Use the lib, Luke!

Using Lite as substitute for Math::BigInt

While Lite is fine when used directly in a script, you also want to make other modules such as Math::BigFloat or Math::BigRat using it. Here is how (you need a fairly recent version of the aforementioned modules to get this to work!):

        # 1
        use Math::BigFloat with => 'Math::BigInt::Lite';

There is no need to ``use Math::BigInt'' or ``use Math::BigInt::Lite'', but you can combine these if you want. For instance, you may want to use Math::BigInt objects in your main script, too.

        # 2
        use Math::BigInt;
        use Math::BigFloat with => 'Math::BigInt::Lite';

Of course, you can combine this with the lib parameter.

        # 3
        use Math::BigFloat with => 'Math::BigInt::Lite', lib => 'GMP,Pari';

If you want to use Math::BigInt's, too, simple add a Math::BigInt before:

        # 4
        use Math::BigInt;
        use Math::BigFloat with => 'Math::BigInt::Lite', lib => 'GMP,Pari';

Notice that the module with the last lib will ``win'' and thus it's lib will be used if the lib is available:

        # 5
        use Math::BigInt lib => 'Bar,Baz';
        use Math::BigFloat with => 'Math::BigInt::Lite', lib => 'Foo';

That would try to load Foo, Bar, Baz and Calc (in that order). Or in other words, Math::BigFloat will try to retain previously loaded libs when you don't specify it one.

Actually, the lib loading order would be ``Bar,Baz,Calc'', and then ``Foo,Bar,Baz,Calc'', but independend of which lib exists, the result is the same as trying the latter load alone, except for the fact that Bar or Baz might be loaded needlessly in an intermidiate step

The old way still works though:

        # 6
        use Math::BigInt lib => 'Bar,Baz';
        use Math::BigFloat;
 
But B<examples #3 and #4 are recommended> for usage.


METHODS

new

        $x = Math::BigInt::Lite->new('1');

Create a new Math::BigInt:Lite object. When the input is not of an suitable simple and small form, an object of the class of $upgrade (typically Math::BigInt) will be returned.

All other methods from BigInt and BigFloat should work as expected.


BUGS

None know yet. Please see also the Math::BigInt manpage.


LICENSE

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.


SEE ALSO

the Math::BigFloat manpage and the Math::Big manpage as well as the Math::BigInt::BitVect manpage, the Math::BigInt::Pari manpage and the Math::BigInt::GMP manpage.

The bignum module.


AUTHORS

(C) by Tels http://bloodgate.com/ 2002-2004.

Information

This site is currently in testing, it is not yet operating using the full database. Until it is officially launched you may wish to visit Help-Site Computer Manuals. After launch, this site (HelpSpy) will replace Help-Site. Information about the spider which is currently trawling the Internet looking for links to add to this directory can be found here.
   

©Copyright Nicholas Reynolds 2004