home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / PariInit.pm < prev    next >
Encoding:
Perl POD Document  |  2001-10-23  |  1.3 KB  |  58 lines

  1. package Math::Pari;
  2.  
  3. my %shift = ( k => 10, K => 10, m => 20, M => 20, g => 30, G=> 30);
  4.  
  5. sub _human2decimal {
  6.   local $_ = shift;
  7.   $_ <<= $shift{$1} if s/([kmg])$//i;
  8.   $_
  9. }
  10.  
  11. sub Math::PariInit::import {
  12.   my $seen;
  13.   CORE::shift;
  14.   my @args = map { 
  15.     /^:?(primes|stack)=(\d+((\.\d*)?[eE][-+]?\d+)?)[kKmMgG]?$/ 
  16.       ? do { ($1 eq 'primes' ? $initprimes : $initmem) = _human2decimal $2;
  17.          $seen++;
  18.          () }
  19.     : $_
  20.   } @_;
  21.   if ($seen && defined &Math::Pari::pari2iv) {
  22.     require Carp;
  23.     Carp::croak(
  24.     "Can't set primelimit and stack size after Math::Pari is loaded")
  25.   }
  26.   require Math::Pari;
  27.   @_ = ('Math::Pari', @args);
  28.   goto &Math::Pari::import;
  29. }
  30.  
  31. 1;
  32.  
  33. =head1 NAME
  34.  
  35. Math::PariInit - load C<Math::Pari> with specified $primelimit and $initmem.
  36.  
  37. =head1 SYNOPSIS
  38.  
  39.   use Math::PariInit qw(:DEFAULT :int primes=1.2e7 stack=1e7 prime)
  40.   $bigprime = prime(500000);
  41.  
  42. =head1 DESCRIPTION
  43.  
  44. C<use Math::PariInit> takes the same arguments as C<use Math::Pari>
  45. with the addition of C<:primes=I<limit>> and C<:stack=I<bytes>> which
  46. specify up to which number the initial list of primes should be
  47. precalculated, and how large should be the arena for PARI calculations.
  48.  
  49. The arguments C<primes> and C<stack> cannot be specified if
  50. Math::Pari is already loaded.
  51.  
  52. =head1 AUTHOR
  53.  
  54. Ilya Zakharevich L<ilya@math.ohio-state.edu>
  55.  
  56. =cut
  57.  
  58.