Math::GMPq

A Perl interface to the GMP library's rational (mpq) functions.
Download

Math::GMPq Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Sisyphus
  • Publisher web site:
  • http://search.cpan.org/~sisyphus/

Math::GMPq Tags


Math::GMPq Description

A Perl interface to the GMP library's rational (mpq) functions. Math::GMPq is a bigrational Perl module utilising the Gnu MP (GMP) library. Basically this module simply wraps all of the 'mpq' (rational number) functions provided by that library. The documentation below extensively plagiarises the GMP documentation (which can be found at http://gmplib.org). See also the Math::GMPq test suite for examples of usage.SYNOPSIS use Math::GMPq qw(:mpq); my $str = '123542/4'; # numerator = 123542 # denominator = 4 my $base = 10; # Create the Math::GMPq object my $bn1 = Rmpq_init(); # Value set to 0/1 # Assign a value. Rmpq_set_str($str, $base); # Remove any factors common to both numerator and # denominator so that gcd(numerator, denominator) == 1. Rmpq_canonicalize($bn1); # or just use the new() function: my $rational = Math::GMPq->new('1234/1179'); # Perform some operations ... see 'FUNCTIONS' below. . . # print out the value held by $bn1 (in octal): print Rmpq_get_str($bn1, 8), " "; # prints '170513/2' # print out the value held by $bn1 (in decimal): print Rmpq_get_str($bn1, 10); # prints '61771/2'. # print out the value held by $bn1 (in base 29) # using the (alternative) Rmpq_out_str() # function. (This function doesn't print a newline.) Rmpq_out_str($bn1, 29); Requirements: · Perl


Math::GMPq Related Software