r24391 - in /branches/upstream/libmath-basecalc-perl: ./ current/ current/lib/ current/lib/Math/ current/t/

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Sat Aug 16 20:36:28 UTC 2008


Author: ansgar-guest
Date: Sat Aug 16 20:36:26 2008
New Revision: 24391

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=24391
Log:
[svn-inject] Installing original source of libmath-basecalc-perl

Added:
    branches/upstream/libmath-basecalc-perl/
    branches/upstream/libmath-basecalc-perl/current/
    branches/upstream/libmath-basecalc-perl/current/Build.PL
    branches/upstream/libmath-basecalc-perl/current/Changes
    branches/upstream/libmath-basecalc-perl/current/MANIFEST
    branches/upstream/libmath-basecalc-perl/current/META.yml
    branches/upstream/libmath-basecalc-perl/current/Makefile.PL
    branches/upstream/libmath-basecalc-perl/current/README
    branches/upstream/libmath-basecalc-perl/current/SIGNATURE
    branches/upstream/libmath-basecalc-perl/current/lib/
    branches/upstream/libmath-basecalc-perl/current/lib/Math/
    branches/upstream/libmath-basecalc-perl/current/lib/Math/BaseCalc.pm
    branches/upstream/libmath-basecalc-perl/current/t/
    branches/upstream/libmath-basecalc-perl/current/t/01_basic_tests.t
    branches/upstream/libmath-basecalc-perl/current/t/99_podcoverage.t

Added: branches/upstream/libmath-basecalc-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/Build.PL?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/Build.PL (added)
+++ branches/upstream/libmath-basecalc-perl/current/Build.PL Sat Aug 16 20:36:26 2008
@@ -1,0 +1,17 @@
+
+use Module::Build;
+
+
+my $build = Module::Build->new
+  (
+   module_name => 'Math::BaseCalc',
+   license => 'perl',
+   build_requires => {
+		      'Test::More' => 0,
+		     },
+   create_makefile_pl => 'traditional',
+   create_readme => 1,
+   sign => 1,
+  );
+
+$build->create_build_script;

Added: branches/upstream/libmath-basecalc-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/Changes?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/Changes (added)
+++ branches/upstream/libmath-basecalc-perl/current/Changes Sat Aug 16 20:36:26 2008
@@ -1,0 +1,28 @@
+Revision history for Perl extension Math::BaseCalc.
+
+ - Modernized the layout of the distribution, including a lib/
+   directory, t/ directory, and using Test::More instead of rolling my
+   own TAP function.  [Todd E. Rinaldo]
+
+1.011  Sat Mar 09 22:46:07 2002
+
+ - Fixed a warning & a couple of tiny doc errors
+
+1.009  Thu Mar 29 21:28:57 EST 2001
+
+ - Now supports non-integers.  Thanks to jdimov at cis.clarion.edu for
+   idea (though I used a different implementation)
+
+ - Handles large numbers (bigger than 2^32, or type 'int').
+   [mizuhara at bellsouth.net (Mizuhara Mokoto)]
+
+1.008  2000/08/28 14:56:09
+
+ - Fixed a problem with from_base() and negative numbers.  They were
+   being treated as positive numbers.  [armengou at fonocom.es (Xavier Armengou)]
+
+
+1.007  Sun May 23 19:23:33 1999
+
+ - original version
+

Added: branches/upstream/libmath-basecalc-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/MANIFEST?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/MANIFEST (added)
+++ branches/upstream/libmath-basecalc-perl/current/MANIFEST Sat Aug 16 20:36:26 2008
@@ -1,0 +1,10 @@
+Build.PL
+Changes
+lib/Math/BaseCalc.pm
+Makefile.PL
+MANIFEST
+META.yml
+README
+t/01_basic_tests.t
+t/99_podcoverage.t
+SIGNATURE    Added here by Module::Build

Added: branches/upstream/libmath-basecalc-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/META.yml?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/META.yml (added)
+++ branches/upstream/libmath-basecalc-perl/current/META.yml Sat Aug 16 20:36:26 2008
@@ -1,0 +1,19 @@
+---
+name: Math-BaseCalc
+version: 1.012
+author:
+  - 'Ken Williams, ken at forum.swarthmore.edu'
+abstract: Convert numbers between various bases
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+build_requires:
+  Test::More: 0
+provides:
+  Math::BaseCalc:
+    file: lib/Math/BaseCalc.pm
+    version: 1.012
+generated_by: Module::Build version 0.280801
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.2.html
+  version: 1.2

Added: branches/upstream/libmath-basecalc-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/Makefile.PL?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/Makefile.PL (added)
+++ branches/upstream/libmath-basecalc-perl/current/Makefile.PL Sat Aug 16 20:36:26 2008
@@ -1,0 +1,14 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01
+use ExtUtils::MakeMaker;
+WriteMakefile
+(
+          'NAME' => 'Math::BaseCalc',
+          'VERSION_FROM' => 'lib/Math/BaseCalc.pm',
+          'PREREQ_PM' => {
+                           'Test::More' => '0'
+                         },
+          'INSTALLDIRS' => 'site',
+          'EXE_FILES' => [],
+          'PL_FILES' => {}
+        )
+;

Added: branches/upstream/libmath-basecalc-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/README?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/README (added)
+++ branches/upstream/libmath-basecalc-perl/current/README Sat Aug 16 20:36:26 2008
@@ -1,0 +1,92 @@
+NAME
+    Math::BaseCalc - Convert numbers between various bases
+
+SYNOPSIS
+      use Math::BaseCalc;
+
+      my $calc = new Math::BaseCalc(digits => [0,1]); #Binary
+      my $bin_string = $calc->to_base(465); # Convert 465 to binary
+
+      $calc->digits('oct'); # Octal
+      my $number = $calc->from_base('1574'); # Convert octal 1574 to decimal
+
+DESCRIPTION
+    This module facilitates the conversion of numbers between various number
+    bases. You may define your own digit sets, or use any of several
+    predefined digit sets.
+
+    The to_base() and from_base() methods convert between Perl numbers and
+    strings which represent these numbers in other bases. For instance, if
+    you're using the binary digit set [0,1], $calc->to_base(5) will return
+    the string "101". $calc->from_base("101") will return the number 5.
+
+    To convert between, say, base 7 and base 36, use the 2-step process of
+    first converting to a Perl number, then to the desired base for the
+    result:
+
+     $calc7  = new Math::BaseCalc(digits=>[0..6]);
+     $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z'];
+
+     $in_base_36 = $calc36->to_base( $calc7->from_base('3506') );
+
+    If you just need to handle regular octal & hexdecimal strings, you
+    probably don't need this module. See the sprintf(), oct(), and hex()
+    Perl functions.
+
+METHODS
+    * new Math::BaseCalc
+    * new Math::BaseCalc(digits=>...)
+        Create a new base calculator. You may specify the digit set to use,
+        by either giving the digits in a list reference (in increasing
+        order, with the 'zero' character first in the list) or by specifying
+        the name of one of the predefined digit sets (see the digit() method
+        below).
+
+    * $calc->to_base(NUMBER)
+        Converts a number to a string representing that number in the
+        associated base.
+
+    * $calc->from_base(STRING)
+        Converts a string representing a number in the associated base to a
+        Perl integer. The behavior when fed strings with characters not in
+        $calc's digit set is currently undefined.
+
+    * $calc->digits
+    * $calc->digits(...)
+        Get/set the current digit set of the calculator. With no arguments,
+        simply returns a list of the characters that make up the current
+        digit set. To change the current digit set, pass a list reference
+        containing the new digits, or the name of a predefined digit set.
+        Currently the predefined digit sets are:
+
+               bin => [0,1],
+               hex => [0..9,'a'..'f'],
+               HEX => [0..9,'A'..'F'],
+               oct => [0..7],
+               64  => ['A'..'Z','a'..'z',0..9,'+','/'],
+               62  => [0..9,'a'..'z','A'..'Z'],
+
+         Examples:
+          $calc->digits('bin');
+          $calc->digits([0..7]);
+          $calc->digits([qw(w a l d o)]);
+
+        If any of your "digits" has more than one character, the behavior is
+        currently undefined.
+
+QUESTIONS
+    The '64' digit set is meant to be useful for Base64 encoding. I took it
+    from the MIME::Base64.pm module. Does it look right? It's sure in a
+    strange order.
+
+AUTHOR
+    Ken Williams, ken at forum.swarthmore.edu
+
+COPYRIGHT
+    This is free software in the colloquial nice-guy sense of the word.
+    Copyright (c) 1999, Ken Williams. You may redistribute and/or modify it
+    under the same terms as Perl itself.
+
+SEE ALSO
+    perl(1).
+

Added: branches/upstream/libmath-basecalc-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/SIGNATURE?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/SIGNATURE (added)
+++ branches/upstream/libmath-basecalc-perl/current/SIGNATURE Sat Aug 16 20:36:26 2008
@@ -1,0 +1,32 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.55.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 649383d6afff05f68dcdf6f1d4feaf634731a0bf Build.PL
+SHA1 1f6b40770b4ffb2af194e79cd091060a8a272120 Changes
+SHA1 90fc65867cc3b1cfabc3202a74e87100b9f04a9b MANIFEST
+SHA1 c290d316938052beb733b9353ded8fbc43067100 META.yml
+SHA1 0f0602a3f257aae5495272346677a53d1ad76e68 Makefile.PL
+SHA1 8132ad35e17ffb205bd21b44d8a1d0e381db6682 README
+SHA1 c10c479c38475aa86ead899c99de393ca1dd2603 lib/Math/BaseCalc.pm
+SHA1 db35c8842667ae08fb3d214266808d28e50721d7 t/01_basic_tests.t
+SHA1 19e797985fada8c25f13ce5f0fb873999c3cbe44 t/99_podcoverage.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.5 (Darwin)
+
+iD8DBQFIZAOkgrvMBLfvlHYRAuerAJ9uHbMN3HpRXPjQgJFFsjOxiyxfTQCfQuBE
+EemDfra9B54GpQOVnMmx/Bs=
+=45KP
+-----END PGP SIGNATURE-----

Added: branches/upstream/libmath-basecalc-perl/current/lib/Math/BaseCalc.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/lib/Math/BaseCalc.pm?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/lib/Math/BaseCalc.pm (added)
+++ branches/upstream/libmath-basecalc-perl/current/lib/Math/BaseCalc.pm Sat Aug 16 20:36:26 2008
@@ -1,0 +1,201 @@
+package Math::BaseCalc;
+
+use strict;
+use Carp;
+use vars qw($VERSION);
+$VERSION = '1.012';
+
+sub new {
+  my ($pack, %opts) = @_;
+  my $self = bless {}, $pack;
+  $self->digits($opts{digits});
+  return $self;
+}
+
+sub digits {
+  my $self = shift;
+  if (@_) {
+    # Set the value
+
+    if (ref $_[0]) {
+      $self->{digits} = [ @{ shift() } ];
+    } else {
+      my $name = shift;
+      my %digitsets = $self->_digitsets;
+      croak "Unrecognized digit set '$name'" unless exists $digitsets{$name};
+      $self->{digits} = $digitsets{$name};
+    }
+
+    # Build the translation table back to numbers
+    @{$self->{trans}}{@{$self->{digits}}} = 0..$#{$self->{digits}};
+
+  }
+  return @{$self->{digits}};
+}
+
+
+sub _digitsets {
+  return (
+      'bin' => [0,1],
+      'hex' => [0..9,'a'..'f'],
+      'HEX' => [0..9,'A'..'F'],
+      'oct' => [0..7],
+      '64'  => ['A'..'Z','a'..'z',0..9,'+','/'],
+      '62'  => [0..9,'a'..'z','A'..'Z'],
+     );
+}
+
+sub from_base {
+  my $self = shift;
+  return -1*$self->from_base(substr($_[0],1)) if $_[0] =~ /^-/; # Handle negative numbers
+  my $str = shift;
+  my $dignum = @{$self->{digits}};
+
+  # Deal with stuff after the decimal point
+  my $add_in = 0;
+  if ($str =~ s/\.(.+)//) {
+    $add_in = $self->from_base(reverse $1)/$dignum**length($1);
+  }
+
+  $str = reverse $str;
+  my $result = 0;
+  while (length $str) {
+    # For large numbers, force result to be an integer (not a float)
+    $result = int($result*$dignum + $self->{trans}{chop $str});
+  }
+
+  # The bizarre-looking next line is necessary for proper handling of very large numbers
+  return $add_in ? $result + $add_in : $result;
+}
+
+sub to_base {
+  my ($self,$num) = @_;
+  return '-'.$self->to_base(-1*$num) if $num<0; # Handle negative numbers
+
+  my $dignum = @{$self->{digits}};
+
+  my $result = '';
+  while ($num>0) {
+    substr($result,0,0) = $self->{digits}[ $num % $dignum ];
+    $num = int ($num/$dignum);
+    #$num = (($num - ($num % $dignum))/$dignum);  # An alternative to the above
+  }
+  return length $result ? $result : $self->{digits}[0];
+}
+
+
+1;
+__END__
+
+
+=head1 NAME
+
+Math::BaseCalc - Convert numbers between various bases
+
+=head1 SYNOPSIS
+
+  use Math::BaseCalc;
+
+  my $calc = new Math::BaseCalc(digits => [0,1]); #Binary
+  my $bin_string = $calc->to_base(465); # Convert 465 to binary
+
+  $calc->digits('oct'); # Octal
+  my $number = $calc->from_base('1574'); # Convert octal 1574 to decimal
+
+=head1 DESCRIPTION
+
+This module facilitates the conversion of numbers between various
+number bases.  You may define your own digit sets, or use any of
+several predefined digit sets.
+
+The to_base() and from_base() methods convert between Perl numbers and
+strings which represent these numbers in other bases.  For instance,
+if you're using the binary digit set [0,1], $calc->to_base(5) will
+return the string "101".  $calc->from_base("101") will return the
+number 5.
+
+To convert between, say, base 7 and base 36, use the 2-step process
+of first converting to a Perl number, then to the desired base for the
+result:
+
+ $calc7  = new Math::BaseCalc(digits=>[0..6]);
+ $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z'];
+
+ $in_base_36 = $calc36->to_base( $calc7->from_base('3506') );
+
+If you just need to handle regular octal & hexdecimal strings, you
+probably don't need this module.  See the sprintf(), oct(), and hex()
+Perl functions.
+
+=head1 METHODS
+
+=over 4
+
+=item * new Math::BaseCalc
+
+=item * new Math::BaseCalc(digits=>...)
+
+Create a new base calculator.  You may specify the digit set to use,
+by either giving the digits in a list reference (in increasing order,
+with the 'zero' character first in the list) or by specifying the name
+of one of the predefined digit sets (see the digit() method below).
+
+=item * $calc->to_base(NUMBER)
+
+Converts a number to a string representing that number in the
+associated base.
+
+=item * $calc->from_base(STRING)
+
+Converts a string representing a number in the associated base to a
+Perl integer.  The behavior when fed strings with characters not in
+$calc's digit set is currently undefined.
+
+=item * $calc->digits
+
+=item * $calc->digits(...)
+
+Get/set the current digit set of the calculator.  With no arguments,
+simply returns a list of the characters that make up the current digit
+set.  To change the current digit set, pass a list reference
+containing the new digits, or the name of a predefined digit set.
+Currently the predefined digit sets are:
+
+       bin => [0,1],
+       hex => [0..9,'a'..'f'],
+       HEX => [0..9,'A'..'F'],
+       oct => [0..7],
+       64  => ['A'..'Z','a'..'z',0..9,'+','/'],
+       62  => [0..9,'a'..'z','A'..'Z'],
+
+ Examples:
+  $calc->digits('bin');
+  $calc->digits([0..7]);
+  $calc->digits([qw(w a l d o)]);
+
+If any of your "digits" has more than one character, the behavior is
+currently undefined.
+
+=back
+
+=head1 QUESTIONS
+
+The '64' digit set is meant to be useful for Base64 encoding.  I took
+it from the MIME::Base64.pm module.  Does it look right?  It's sure in
+a strange order.
+
+=head1 AUTHOR
+
+Ken Williams, ken at forum.swarthmore.edu
+
+=head1 COPYRIGHT
+
+This is free software in the colloquial nice-guy sense of the word.
+Copyright (c) 1999, Ken Williams.  You may redistribute and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+perl(1).
+
+=cut

Added: branches/upstream/libmath-basecalc-perl/current/t/01_basic_tests.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/t/01_basic_tests.t?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/t/01_basic_tests.t (added)
+++ branches/upstream/libmath-basecalc-perl/current/t/01_basic_tests.t Sat Aug 16 20:36:26 2008
@@ -1,0 +1,79 @@
+#! perl
+
+use strict;
+use warnings;
+use Test::More tests =>13;
+use_ok('Math::BaseCalc');
+
+my $calc = new Math::BaseCalc(digits=>[0,1]);
+isa_ok($calc, "Math::BaseCalc");
+
+{
+    my $result = $calc->from_base('01101');
+    is($result, 13, "from_base = 13");
+}
+
+{
+    $calc->digits('bin');
+    my $result = $calc->from_base('1101');
+    is($result, 13, "1101 into decimal");
+}
+
+{
+    my $result = $calc->to_base(13);
+    is($result, '1101', "convert back to our base (binary)");
+}
+
+{
+    $calc->digits('hex');
+    my $result = $calc->to_base(46);
+    is($result, '2e', "convert 46 into hex(2e)");
+}
+
+{
+    $calc->digits([qw(i  a m  v e r y  p u n k)]);
+    my $result = $calc->to_base(13933);
+    is($result, 'krap', "base 11 with custom letters for each digit. Becomes a517 which is krap with custom letters");
+}
+
+{
+    $calc->digits('hex');
+    my $result = $calc->to_base('-17');
+    is($result, '-11', "negative decimal (-17) into hex (-11)");
+}
+
+{
+    $calc->digits('hex');
+    my $result = $calc->from_base('-11');
+    is($result, '-17', "negative hex (-11) into decimal (-17)");
+}
+
+{
+    $calc->digits('hex');
+    my $result = $calc->from_base('-11.05');
+    is($result, '-17.01953125', "negative float number in hex to b10 (-11.05 to -17....");
+}
+
+{
+    $calc->digits([0..6]);
+    my $result = $calc->from_base('0.1');
+    is($result, (1/7), "base 6 float (.1) converts to decimal (1/7).");
+}
+
+{
+    # Test large numbers
+    $calc->digits('hex');
+    my $r1 = $calc->to_base(2**55 + 5);
+    my $result = $calc->from_base($calc->to_base(2**55 + 5));
+    #warn "res: $r1, $result";
+    is($result, 2**55 + 5, "hex (2**55 + 5) into hex then back");
+}
+
+{
+  $calc->digits('bin');
+  my $first  = $calc->from_base('1110111');
+  my $second = $calc->from_base('1010110');
+  my $third = $calc->to_base($first * $second);
+  is($third, '10011111111010', "1110111 x 1010110 = 10011111111010");
+}
+

Added: branches/upstream/libmath-basecalc-perl/current/t/99_podcoverage.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmath-basecalc-perl/current/t/99_podcoverage.t?rev=24391&op=file
==============================================================================
--- branches/upstream/libmath-basecalc-perl/current/t/99_podcoverage.t (added)
+++ branches/upstream/libmath-basecalc-perl/current/t/99_podcoverage.t Sat Aug 16 20:36:26 2008
@@ -1,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_coverage_ok();




More information about the Pkg-perl-cvs-commits mailing list