Sisyphus repositório
Última atualização: 1 outubro 2023 | SRPMs: 18631 | Visitas: 37886916
en ru br
ALT Linux repositórios
S:1.14-alt1
5.0: 1.4.75-alt1
4.1: 1.4.75-alt1
4.0: 1.2.59-alt1

Group :: Desenvolvimento/Perl
RPM: perl-Math-BaseCnv

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs e FR  Repocop 

Math-BaseCnv-1.8.B59BrZX/000075500000000000000000000000001160015652700146775ustar00rootroot00000000000000Math-BaseCnv-1.8.B59BrZX/BaseCnv.pm000064400000000000000000000437631160015652700165730ustar00rootroot00000000000000# 3159mLT: Math::BaseCnv.pm by PipStuart <Pip@CPAN.Org> to CoNVert between arbitrary number Bases. I'm totally addicted to bass!
package Math::BaseCnv;
require Exporter;
use strict;
use warnings;
use base qw(Exporter);
use Math::BigInt;
use Memoize; memoize('summ'); memoize('fact'); memoize('choo');
# only export cnv() for 'use Math::BaseCnv;' && all other stuff optionally
our @EXPORT = qw(cnv ) ;
our @EXPORT_OK = qw( dec hex b10 b64 b64sort dig diginit summ fact choo) ;
our %EXPORT_TAGS = ( 'all' =>[ qw(cnv dec hex b10 b64 b64sort dig diginit summ fact choo) ],
'hex' =>[ qw( dec hex ) ],
'b64' =>[ qw(cnv b10 b64 b64sort ) ],
'dig' =>[ qw( dig diginit) ],
'sfc' =>[ qw( summ fact choo) ] );
our $VERSION = '1.8.B59BrZX'; our $PTVR = $VERSION; $PTVR =~ s/^\d+\.\d+\.//; # Please see `perldoc Time::PT` for an explanation of $PTVR.
my $d2bs = ''; my %bs2d = (); my $nega = '';
my %digsets = (
'usr' => [], # this will be assigned if a dig(\@newd) call is made
'bin' => ['0', '1'],
'oct' => ['0'..'7'],
'dec' => ['0'..'9'],
'hex' => ['0'..'9', 'a'..'f'],
'HEX' => ['0'..'9', 'A'..'F'],
'b62' => ['0'..'9', 'a'..'z', 'A'..'Z'],
'b64' => ['0'..'9', 'A'..'Z', 'a'..'z', '.', '_'], # month:C:12 day:V:31
'm64' => ['A'..'Z', 'a'..'z', '0'..'9', '+', '/'], # 0-63 from MIME::Base64
'iru' => ['A'..'Z', 'a'..'z', '0'..'9', '[', ']'], # P10 server-server protocol used by IRCu daemon
'url' => ['A'..'Z', 'a'..'z', '0'..'9', '-', '_'], # MIME::Base64::URLSafe which avoids %2B && %2F expansions of '+' && '/' respectively
'rex' => ['A'..'Z', 'a'..'z', '0'..'9', '!', '-'], # Regular EXpression variant
'id0' => ['A'..'Z', 'a'..'z', '0'..'9', '_', '-'], # IDentifier style 0
'id1' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '_'], # IDentifier style 1
'xnt' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '-'], # XML Name Tokens (Nmtoken)
'xid' => ['A'..'Z', 'a'..'z', '0'..'9', '_', ':'], # XML identifiers (Name )
'b85' => ['0'..'9', 'A'..'Z', 'a'..'z', '!', '#', # RFC 1924 for IPv6 addresses, might need to return Math::BigInt objs
'$', '%', '&', '(', ')', '*', '+', '-', ';', '<', '=', '>', '?', '@', '^', '_', '`', '{', '|', '}', '~'],
);
sub bs2init { %bs2d = (); for(my $i = 0; $i < @{ $digsets{$d2bs} }; $i++) { $bs2d{${ $digsets{$d2bs} }[$i]} = $i; } } # build hash digit chars => array indices
sub diginit { $d2bs = 'b64'; bs2init(); } # reset digit character list to initial Dflt
sub dig { # assign a new digit character list
return( @{ $digsets{$d2bs} } ) unless(@_);
if(ref $_[0]) { $d2bs = 'usr'; $digsets{$d2bs} = [ @{ shift() } ]; }
else { my $setn = shift(); return(-1) unless(exists $digsets{$setn}); $d2bs = $setn; }
diginit() unless(@{ $digsets{$d2bs} });
bs2init(); }
sub cnv__10 { # convert from some number base to decimal fast
my $t = shift || '0'; my $s = shift || 64; my $n = Math::BigInt->new();
$nega = ''; $nega = '-' if($t =~ s/^-//);
for(split(//, $t)) { return(-1) unless(exists $bs2d{$_}); }
while(length($t)) { $n += $bs2d{substr($t,0,1,'')}; $n *= $s; }
return($nega . int($n / $s)); }
sub cnv10__ { # convert from decimal to some number base fast
my $n = Math::BigInt->new(shift || '0'); my $s = shift || 64; my $t = '';
return(-1) if($s > @{ $digsets{$d2bs} });
$nega = ''; $nega = '-' if($n =~ s/^-//);
while($n) { $t = $digsets{$d2bs}->[($n % $s)] . $t; $n = int($n / $s); }
if(length($t)) { $t = $nega . $t; }
else { $t = $digsets{$d2bs}->[0]; }
return($t); }
sub dec { return(cnv__10(uc(shift), 16)); }#shortcut for hexadecimal -> decimal
sub hex { return(cnv10__( shift, 16)); }#shortcut for decimal -> hex
sub b10 { return(cnv__10( shift, 64)); }#shortcut for base64 -> decimal
sub b64 { return(cnv10__( shift, 64)); }#shortcut for decimal -> base64
sub b64sort { return( map { b64($_) } sort { $a <=> $b } map { b10($_) } @_ ); }
sub cnv { # CoNVert between any number base
my $numb = shift; return(-1) unless(defined($numb) && length($numb));
my $fbas = shift; my $tbas = shift; my $rslt = ''; my $temp = 0;
return($digsets{$d2bs}->[0]) if($numb =~ /^-?0+$/); # lots of (negative?) zeros is just zero
if(!defined($tbas)) { # makeup reasonable values for missing params
if(!defined($fbas)) { $fbas = 10; $tbas = 16;
if ($numb =~ /^0x/i || ($numb =~ /[A-F]/i && $numb =~ /^[0-9A-F]+$/i )) { $fbas = 16; $tbas = 10; }
elsif($numb =~ /[G-Z._]/i && $numb =~ /^[0-9A-Z._]+$/i) { $fbas = 64; $tbas = 10; }
elsif($numb =~ /\D/) { print "!*EROR*! Can't determine reasonable FromBase && ToBase from number:$numb!\n"; }
} else { $tbas = $fbas; $fbas = 10; }
}
$fbas = 16 if($fbas =~ /\D/); $tbas = 10 if($tbas =~ /\D/);
if($fbas == 16) { $numb =~ s/^0x//i; $numb = uc($numb); }
return(-1) if($fbas < 2 || $tbas < 2); # invalid base error
$numb = cnv__10($numb, $fbas) if($numb =~ /\D/ || $fbas != 10);
$numb = cnv10__($numb, $tbas) if( $tbas != 10);
return($numb);
}
sub summ { # simple function to calculate summation down to 1
my $summ = shift; return(0) unless(defined($summ) && $summ && ($summ > 0)); my $answ = Math::BigInt->new($summ);while(--$summ){$answ +=$summ;} return($answ);
}
sub fact { # simple function to calculate factorials
my $fact = shift; return(0) unless(defined($fact) && $fact && ($fact > 0)); my $answ = Math::BigInt->new($fact);while(--$fact){$answ *=$fact;} return($answ);
}
sub choo { # simple function to calculate n choose m (i.e., (n! / (m! * (n - m)!)))
my $ennn = Math::BigInt->new(shift); my $emmm = Math::BigInt->new(shift);
return(0) unless(defined($ennn) && defined($emmm) && $ennn && $emmm && ($ennn != $emmm));
($ennn, $emmm) = ($emmm, $ennn) if($ennn < $emmm); my $diff = Math::BigInt->new($ennn - $emmm); my $answ = Math::BigInt->new(fact($ennn));
my $mfct = Math::BigInt->new( fact( $emmm));my $dfct = Math::BigInt->new(fact($diff));
$mfct *= $dfct; return(0) unless($mfct);
$answ /= $mfct; return($answ);
}
diginit(); # initialize the Dflt digit set whenever BaseCnv is used
127;
=head1 NAME

Math::BaseCnv - fast functions to CoNVert between number Bases

=head1 VERSION

This documentation refers to version 1.8.B59BrZX of Math::BaseCnv, which was released on Mon May 9 11:53:35:33 2011.

=head1 SYNOPSIS

use Math::BaseCnv;

# CoNVert 63 from base-10 (decimal) to base- 2 (binary )
$binary_63 = cnv( 63, 10, 2 );
# CoNVert 111111 from base- 2 (binary ) to base-16 (hex )
$hex_63 = cnv( 111111, 2, 16 );
# CoNVert 3F from base-16 (hex ) to base-10 (decimal)
$decimal_63 = cnv( '3F', 16, 10 );
print "63 dec->bin $binary_63 bin->hex $hex_63 hex->dec $decimal_63\n";

=head1 DESCRIPTION

BaseCnv provides a few simple functions for converting between arbitrary number bases. It is as fast as I currently know how to make it (of course
relying only on the lovely Perl). If you would rather utilize an object syntax for number-base conversion, please see Ken Williams'
<Ken@Forum.Swarthmore.Edu> fine L<Math::BaseCalc> module.

=head1 PURPOSE

The reason I created BaseCnv was that I needed a simple way to convert quickly between the 3 number bases I use most (10, 16, && 64). It turned out
that it was trivial to handle any arbitrary number base that is represented as characters. High-bit ASCII has proven somewhat problemmatic but at least
BaseCnv can simply && realiably convert between any possible base between 2 && 64 (or 85). I'm happy with it && employ b64() in places I probably
shouldn't now =).

=head1 USAGE

=head2 cnv($numb[,$from[,$tobs]])

CoNVert the number contained in $numb from its current number base ($from) into the result number base ($tobs).

B<When only $numb is provided as a parameter:>

If $numb only contains valid decimal (base 10) digits, it will be converted to hexadecimal (base 16).

If $numb only contains valid hexadecimal (base 16) digits or begins with '0x', it will be it will be converted to decimal (base 10).

B<When only $numb && $from are provided as parameters:>

cnv() assumes that $numb is already in decimal format && uses $from as the $tobs.

B<When all three parameters are provided:>

The normal (&& most clear) usage of cnv() is to provide all three parameters where $numb is converted from $from base to $tobs.

cnv() is the only function that is exported from a normal 'use Math::BaseCnv;' command. The other functions below can be imported to local namespaces
explicitly or with the following tags:

:all - every function described here
:hex - only dec() && hex()
:b64 - only b10() && b64() && b64sort() && cnv()
:dig - only dig() && diginit()
:sfc - only summ(), fact(), && choo()

=head2 b10($b64n)

A shortcut to convert the number given as a parameter ($b64n) from base 64 to decimal (base 10).

=head2 b64($b10n)

A shortcut to convert the number given as a parameter ($b10n) from decimal (base 10) to base 64.

=head2 b64sort(@b64s)

A way to sort b64 strings as though they were decimal numbers.

=head2 dec($b16n)

A shortcut to convert the number given as a parameter ($b16n) from hexadecimal (base 16) to decimal (base 10).

=head2 hex($b10n)

A shortcut to convert the number given as a parameter ($b10n) from decimal (base 10) to hexadecimal (base 16).

Please read the L<"NOTES"> regarding hex().

=head2 dig(\@newd)

Assign the new digit character list to be used in place of the default one. dig() can also alternately accept a string name matching one of the
following predefined digit sets:

'bin' => ['0', '1']
'oct' => ['0'..'7']
'dec' => ['0'..'9']
'hex' => ['0'..'9', 'a'..'f']
'HEX' => ['0'..'9', 'A'..'F']
'b62' => ['0'..'9', 'a'..'z', 'A'..'Z']
'b64' => ['0'..'9', 'A'..'Z', 'a'..'z', '.', '_']
'm64' => ['A'..'Z', 'a'..'z', '0'..'9', '+', '/'] # MIME::Base64
'iru' => ['A'..'Z', 'a'..'z', '0'..'9', '[', ']'] # IRCu
'url' => ['A'..'Z', 'a'..'z', '0'..'9', '-', '_'] # MIME::Base64::URLSafe
'rex' => ['A'..'Z', 'a'..'z', '0'..'9', '!', '-'] # RegEx
'id0' => ['A'..'Z', 'a'..'z', '0'..'9', '_', '-'] # ID 0
'id1' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '_'] # ID 1
'xnt' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '-'] # XML Nmtoken
'xid' => ['A'..'Z', 'a'..'z', '0'..'9', '_', ':'] # XML ID Name
'b85' => ['0'..'9', 'A'..'Z', 'a'..'z', '!', '#', # RFC 1924 for
'$', '%', '&', '(', ')', '*', '+', '-', # IPv6 addrs
';', '<', '=', '>', '?', '@', '^', '_', # like in
'`', '{', '|', '}', '~' ] # Math::Base85

If no \@newd list or digit set name is provided as a parameter, dig() returns the current character list. It's fine to have many more characters
in your current digit set than will be used with your conversions (e.g., using dig('b64') works fine for any cnv() call with $from && $tobs params
less than or equal to 64).

An example of a \@newd parameter for a specified alternate digit set for base 9 conversions is:

dig( [ qw( n a c h o z y u m ) ] );

=head2 diginit()

Resets the used digit list to the initial default order of the predefined digit set: 'b64'. This is simply a shortcut for calling dig('b64') for
reinitialization purposes.

=head2 summ($numb)

A simple function to calculate a memoized BigInt summation of $numb down to 1.

=head2 fact($numb)

A simple function to calculate a memoized BigInt factorial of $numb.

=head2 choo($ennn, $emmm)

A simple function to calculate a memoized BigInt function of $ennn choose $emmm.

=head1 NOTES

The Perl builtin hex() function takes a hex string as a parameter && returns the decimal value (FromBase = 16, ToBase = 10) but this notation seems
counter-intuitive to me since a simple reading of the code suggests that a hex() function will turn your parameter into hexadecimal (i.e., It sounds
like Perl's hex() will hexify your parameter but it does not.) so I've decided (maybe foolishly) to invert the notation for my similar functions since
it makes more sense to me this way && will be easier to remember (I've had to lookup hex() in the Camel book many times already which was part of the
impetus for this module... as well as the gut reaction that sprintf() is not a proper natural inverse function for hex()).

This means that my b64() function takes a decimal number as a parameter && returns the base64 equivalent (FromBase = 10, ToBase = 64) && my b10()
function takes a base64 number (string) && returns the decimal value (FromBase = 64, ToBase = 10). My hex() function overloads Perl's builtin version
with this opposite behavior so my dec() function behaves like Perl's normal hex() function. I know it's confusing && maybe bad form of me to do this
but I like it so much better this way that I'd rather go against the grain.

Please think of my dec() && hex() functions as meaning decify && hexify. Also the pronunciation of dec() is 'dess' (!'deck' which would be the inverse
of 'ink' which -- && ++ already do so well). After reading the informative Perl module etiquette guidelines, I now appreciate the need to export as
little as is necessary by default. So to be responsible, I have limited BaseCnv exporting to only cnv() under normal circumstances. Please
specify the other functions you'd like to import into your namespace or use the tags described above in the cnv() section like:

'use Math::BaseCnv qw(:all !:hex);'

Error checking is minimal.

This module does not handle fractional number inputs because I like using the dot (.) character as a standard base64 digit since it makes for clean filenames.

summ(), fact(), && choo() are general Math function utilities which are unrelated to number-base conversion but I didn't feel like making another separate
module just for them so they snuck in here.

I hope you find Math::BaseCnv useful. Please feel free to e-mail me any suggestions or coding tips or notes of appreciation ("app-ree-see-ay-shun").
Thank you. TTFN.

=head1 2DU

=over 2

=item - better error checking

=item - handle fractional parts? umm but I like using '.' as a b64 char so ',' comma or some other separator?

=item - What else does BaseCnv need?

=back

=head1 CHANGES

Revision history for Perl extension Math::BaseCnv:

=over 2

=item - 1.8.B59BrZX Mon May 9 11:53:35:33 2011

* updated 'url' digit set to URLSafe to resolve HTTPS://RT.CPAN.Org/Ticket/Display.html?id=60125

* updated license copyright years (already had GPLv3)

=item - 1.6.A6FGHKE Tue Jun 15 16:17:20:14 2010

* bumped minor version number so they'll keep ascending (without PT comprehension)

=item - 1.4.A6FAbEb Tue Jun 15 10:37:14:37 2010

* added Math::BigInt code for >64-bit number-base conversions

* added a bunch more DigitSets: IRCu, URL, RegEx, identifier variants, XML Nmtoken, && XML ID Name

=item - 1.4.75O6Pbr Thu May 24 06:25:37:53 2007

* added Test::Pod(::Coverage)? tests && PREREQ entries

* added b85 for IPv6, gen'd META.yml (w/ newline before EOF), up'd minor ver

=item - 1.2.68J9uJQ Sat Aug 19 09:56:19:26 2006

* added b64sort() && put pod at bottom

=item - 1.2.59M7mRX Thu Sep 22 07:48:27:33 2005

* testing Make as primary and BuildPL backup (needing rename for dot)

=item - 1.2.59IBlgw Sun Sep 18 11:47:42:58 2005

* testing just using Module::Build instead of MakeMaker

* fixed test 12 which was failing on AMD64

* added Build.PL to pkg

=item - 1.2.54HK3pB Sun Apr 17 20:03:51:11 2005

* removed 128 digit-set since some hi-bit chars cause probs on Win32

* made bin/cnv only executable to go in EXE_FILES

* made Math::BaseCalc a link in pod && updated License

=item - 1.2.45UC8fo Sun May 30 12:08:41:50 2004

* tidied POD && upped minor version number since CPAN can't read PTVR

=item - 1.0.44E9ljP Wed Apr 14 09:47:45:25 2004

* added test for div-by-zero error in choo()

* added summ()

=item - 1.0.446EIbS Tue Apr 6 14:18:37:28 2004

* snuck in fact() && choo()

=item - 1.0.42REDir Fri Feb 27 14:13:44:53 2004

* changed test.pl to hopefully pass MSWin32-x86-multi-thread

=item - 1.0.428LV46 Sun Feb 8 21:31:04:06 2004

* broke apart CHANGES to descend chronologically

* made dec() auto uppercase param since dec(a) was returning 36 instead of 10

=item - 1.0.41M4GMP Thu Jan 22 04:16:22:25 2004

* put cnv in bin/ as EXE_FILES

=item - 1.0.418BEPc Thu Jan 8 11:14:25:38 2004

* testing new e auto-gen MANIFEST(.SKIP)?

=item - 1.0.3CNH37s Tue Dec 23 17:03:07:54 2003

* updated POD

=item - 1.0.3CG3dIx Tue Dec 16 03:39:18:59 2003

* normalized base spelling

=item - 1.0.3CD1Vdd Sat Dec 13 01:31:39:39 2003

* added ABSTRACT section to WriteMakeFile()

* changed synopsis example

* updated all POD indenting

=item - 1.0.3CCA5Mi Fri Dec 12 10:05:22:44 2003

* removed indenting from POD NAME field

=item - 1.0.3CB7M43 Thu Dec 11 07:22:04:03 2003

* updated package to coincide with Time::Fields release

=item - 1.0.39B36Lv Thu Sep 11 03:06:21:57 2003

* synchronized POD with README documentation using new e utility

* templatized package compilation

* fixed boundary bugs

=item - 1.0.37SLNGN Mon Jul 28 21:23:16:23 2003

* first version (&& my first Perl module... yay!) put on CPAN

=item - 1.0.37JKj3w Sat Jul 19 20:45:03:58 2003

* reworked interface from shell utility to package

=item - 1.0.3159mLT Sun Jan 5 09:48:21:29 2003

* original version

=back

=head1 INSTALL

Please run:

`perl -MCPAN -e "install Math::BaseCnv"`

or uncompress the package && run:

`perl Makefile.PL; make; make test; make install`
or if you don't have `make` but Module::Build is installed
`perl Build.PL; perl Build; perl Build test; perl Build install`

=head1 LICENSE

Most source code should be Free! Code I have lawful authority over is && shall be!
Copyright:(c) 2003-2011, Pip Stuart.
Copyleft : This software is licensed under the GNU General Public License (version 3). Please consult the Free Software Foundation (HTTP://FSF.Org)
for important information about your freedom.

=head1 AUTHOR

Pip Stuart <Pip@CPAN.Org>

=cut
Math-BaseCnv-1.8.B59BrZX/Build.PL000064400000000000000000000020501160015652700161700ustar00rootroot00000000000000#!/usr/bin/perl
use Module::Build;
my $mbld = Module::Build->new(
# 'module_name' => 'Math::BaseCnv',
'dist_name' => 'Math-BaseCnv',
# 'dist_version_from' => 'BaseCnv.pm',
'dist_version' => '1.8.B59BrZX',
'dist_abstract' => 'fast functions to CoNVert between number Bases',
'dist_author' => 'Pip Stuart <Pip@CPAN.Org>',
# 'create_readme' => '1',
# 'create_makefile_pl' => '1', # 'traditional',
'license' => 'gpl',
'script_files' => {
'bin/cnv' => '1',
},
'pm_files' => {
'BaseCnv.pm' => 'lib/Math/BaseCnv.pm',
},
'requires' => {
'Math::BigInt' => '0',
'Memoize' => '0',
'Test' => '0',
'Test::Pod' => '0',
'Test::Pod::Coverage' => '0',
},
);
$mbld->create_build_script();Math-BaseCnv-1.8.B59BrZX/CHANGES000064400000000000000000000063351160015652700157010ustar00rootroot00000000000000CHANGES
Revision history for Perl extension Math::BaseCnv:

- 1.8.B59BrZX Mon May 9 11:53:35:33 2011
* updated 'url' digit set to URLSafe to resolve
HTTPS://RT.CPAN.Org/Ticket/Display.html?id=60125

* updated license copyright years (already had GPLv3)

- 1.6.A6FGHKE Tue Jun 15 16:17:20:14 2010
* bumped minor version number so they'll keep ascending (without PT
comprehension)

- 1.4.A6FAbEb Tue Jun 15 10:37:14:37 2010
* added Math::BigInt code for >64-bit number-base conversions

* added a bunch more DigitSets: IRCu, URL, RegEx, identifier variants,
XML Nmtoken, && XML ID Name

- 1.4.75O6Pbr Thu May 24 06:25:37:53 2007
* added Test::Pod(::Coverage)? tests && PREREQ entries

* added b85 for IPv6, gen'd META.yml (w/ newline before EOF), up'd
minor ver

- 1.2.68J9uJQ Sat Aug 19 09:56:19:26 2006
* added b64sort() && put pod at bottom

- 1.2.59M7mRX Thu Sep 22 07:48:27:33 2005
* testing Make as primary and BuildPL backup (needing rename for dot)

- 1.2.59IBlgw Sun Sep 18 11:47:42:58 2005
* testing just using Module::Build instead of MakeMaker

* fixed test 12 which was failing on AMD64

* added Build.PL to pkg

- 1.2.54HK3pB Sun Apr 17 20:03:51:11 2005
* removed 128 digit-set since some hi-bit chars cause probs on Win32

* made bin/cnv only executable to go in EXE_FILES

* made Math::BaseCalc a link in pod && updated License

- 1.2.45UC8fo Sun May 30 12:08:41:50 2004
* tidied POD && upped minor version number since CPAN can't read PTVR

- 1.0.44E9ljP Wed Apr 14 09:47:45:25 2004
* added test for div-by-zero error in choo()

* added summ()

- 1.0.446EIbS Tue Apr 6 14:18:37:28 2004
* snuck in fact() && choo()

- 1.0.42REDir Fri Feb 27 14:13:44:53 2004
* changed test.pl to hopefully pass MSWin32-x86-multi-thread

- 1.0.428LV46 Sun Feb 8 21:31:04:06 2004
* broke apart CHANGES to descend chronologically

* made dec() auto uppercase param since dec(a) was returning 36
instead of 10

- 1.0.41M4GMP Thu Jan 22 04:16:22:25 2004
* put cnv in bin/ as EXE_FILES

- 1.0.418BEPc Thu Jan 8 11:14:25:38 2004
* testing new e auto-gen MANIFEST(.SKIP)?

- 1.0.3CNH37s Tue Dec 23 17:03:07:54 2003
* updated POD

- 1.0.3CG3dIx Tue Dec 16 03:39:18:59 2003
* normalized base spelling

- 1.0.3CD1Vdd Sat Dec 13 01:31:39:39 2003
* added ABSTRACT section to WriteMakeFile()

* changed synopsis example

* updated all POD indenting

- 1.0.3CCA5Mi Fri Dec 12 10:05:22:44 2003
* removed indenting from POD NAME field

- 1.0.3CB7M43 Thu Dec 11 07:22:04:03 2003
* updated package to coincide with Time::Fields release

- 1.0.39B36Lv Thu Sep 11 03:06:21:57 2003
* synchronized POD with README documentation using new e utility

* templatized package compilation

* fixed boundary bugs

- 1.0.37SLNGN Mon Jul 28 21:23:16:23 2003
* first version (&& my first Perl module... yay!) put on CPAN

- 1.0.37JKj3w Sat Jul 19 20:45:03:58 2003
* reworked interface from shell utility to package

- 1.0.3159mLT Sun Jan 5 09:48:21:29 2003
* original version

Math-BaseCnv-1.8.B59BrZX/MANIFEST000064400000000000000000000003011160015652700160220ustar00rootroot00000000000000BaseCnv.pm
MANIFEST
t/00podc.t
t/01base.t
bin/cnv
bin/dec
bin/hex
bin/b10
bin/b64
bin/summ
bin/fact
bin/choo
t/00pod.t
ex/synopsis.pl
MANIFEST.SKIP
README
CHANGES
META.yml
Makefile.PL
Build.PL
Math-BaseCnv-1.8.B59BrZX/MANIFEST.SKIP000064400000000000000000000001251160015652700165730ustar00rootroot00000000000000\bCVS\b
^Makefile$
^MANIFEST\.bak$
^updt.*$
\.bak$
\.swp$
\..*\.swp$
\b\.xvpics\b
~$
Math-BaseCnv-1.8.B59BrZX/META.yml000064400000000000000000000007501160015652700161520ustar00rootroot00000000000000--- #YAML:1.0
name: Math-BaseCnv
abstract: fast functions to CoNVert between number Bases
version: 1.8.B59BrZX
author:
- Pip Stuart <Pip@CPAN.Org>
license: gpl
distribution_type: module
requires:
Math::BigInt: 0
Memoize: 0
recommends:
build_requires:
Test: 0
Test::Pod: 0
Test::Pod::Coverage: 0
urls:
license: HTTP://FSF.Org/licensing/licenses/gpl.txt
meta-spec:
version: 1.3
url: HTTP://Module-Build.SourceForge.Net/META-spec-v1.3.html
generated_by: e pkg v1.0.A2RJrKV
Math-BaseCnv-1.8.B59BrZX/Makefile.PL000064400000000000000000000013641160015652700166550ustar00rootroot00000000000000use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Math::BaseCnv',
'VERSION' => '1.8.B59BrZX',
'ABSTRACT' => 'fast functions to CoNVert between number Bases',
'AUTHOR' => 'Pip Stuart <Pip@CPAN.Org>',
'EXE_FILES' => [
'bin/cnv',
],
'PREREQ_PM' => {
'Math::BigInt' => 0,
'Memoize' => 0,
'Test' => 0,
'Test::Pod' => 0,
'Test::Pod::Coverage' => 0,
}, # Module::Name => 1.1,
'dist' => { 'COMPRESS' => 'gzip', 'SUFFIX' => 'tgz' },
);Math-BaseCnv-1.8.B59BrZX/README000064400000000000000000000301261160015652700155610ustar00rootroot00000000000000NAME
Math::BaseCnv - fast functions to CoNVert between number Bases

VERSION
This documentation refers to version 1.8.B59BrZX of Math::BaseCnv, which
was released on Mon May 9 11:53:35:33 2011.

SYNOPSIS
use Math::BaseCnv;

# CoNVert 63 from base-10 (decimal) to base- 2 (binary )
$binary_63 = cnv( 63, 10, 2 );
# CoNVert 111111 from base- 2 (binary ) to base-16 (hex )
$hex_63 = cnv( 111111, 2, 16 );
# CoNVert 3F from base-16 (hex ) to base-10 (decimal)
$decimal_63 = cnv( '3F', 16, 10 );
print "63 dec->bin $binary_63 bin->hex $hex_63 hex->dec $decimal_63\n";

DESCRIPTION
BaseCnv provides a few simple functions for converting between arbitrary
number bases. It is as fast as I currently know how to make it (of
course relying only on the lovely Perl). If you would rather utilize an
object syntax for number-base conversion, please see Ken Williams'
<Ken@Forum.Swarthmore.Edu> fine Math::BaseCalc module.

PURPOSE
The reason I created BaseCnv was that I needed a simple way to convert
quickly between the 3 number bases I use most (10, 16, && 64). It turned
out that it was trivial to handle any arbitrary number base that is
represented as characters. High-bit ASCII has proven somewhat
problemmatic but at least BaseCnv can simply && realiably convert
between any possible base between 2 && 64 (or 85). I'm happy with it &&
employ b64() in places I probably shouldn't now =).

USAGE
cnv($numb[,$from[,$tobs]])
CoNVert the number contained in $numb from its current number base
($from) into the result number base ($tobs).

When only $numb is provided as a parameter:

If $numb only contains valid decimal (base 10) digits, it will be
converted to hexadecimal (base 16).

If $numb only contains valid hexadecimal (base 16) digits or begins with
'0x', it will be it will be converted to decimal (base 10).

When only $numb && $from are provided as parameters:

cnv() assumes that $numb is already in decimal format && uses $from as
the $tobs.

When all three parameters are provided:

The normal (&& most clear) usage of cnv() is to provide all three
parameters where $numb is converted from $from base to $tobs.

cnv() is the only function that is exported from a normal 'use
Math::BaseCnv;' command. The other functions below can be imported to
local namespaces explicitly or with the following tags:

:all - every function described here
:hex - only dec() && hex()
:b64 - only b10() && b64() && b64sort() && cnv()
:dig - only dig() && diginit()
:sfc - only summ(), fact(), && choo()

b10($b64n)
A shortcut to convert the number given as a parameter ($b64n) from base
64 to decimal (base 10).

b64($b10n)
A shortcut to convert the number given as a parameter ($b10n) from
decimal (base 10) to base 64.

b64sort(@b64s)
A way to sort b64 strings as though they were decimal numbers.

dec($b16n)
A shortcut to convert the number given as a parameter ($b16n) from
hexadecimal (base 16) to decimal (base 10).

hex($b10n)
A shortcut to convert the number given as a parameter ($b10n) from
decimal (base 10) to hexadecimal (base 16).

Please read the "NOTES" regarding hex().

dig(\@newd)
Assign the new digit character list to be used in place of the default
one. dig() can also alternately accept a string name matching one of the
following predefined digit sets:

'bin' => ['0', '1']
'oct' => ['0'..'7']
'dec' => ['0'..'9']
'hex' => ['0'..'9', 'a'..'f']
'HEX' => ['0'..'9', 'A'..'F']
'b62' => ['0'..'9', 'a'..'z', 'A'..'Z']
'b64' => ['0'..'9', 'A'..'Z', 'a'..'z', '.', '_']
'm64' => ['A'..'Z', 'a'..'z', '0'..'9', '+', '/'] # MIME::Base64
'iru' => ['A'..'Z', 'a'..'z', '0'..'9', '[', ']'] # IRCu
'url' => ['A'..'Z', 'a'..'z', '0'..'9', '-', '_'] # MIME::Base64::URLSafe
'rex' => ['A'..'Z', 'a'..'z', '0'..'9', '!', '-'] # RegEx
'id0' => ['A'..'Z', 'a'..'z', '0'..'9', '_', '-'] # ID 0
'id1' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '_'] # ID 1
'xnt' => ['A'..'Z', 'a'..'z', '0'..'9', '.', '-'] # XML Nmtoken
'xid' => ['A'..'Z', 'a'..'z', '0'..'9', '_', ':'] # XML ID Name
'b85' => ['0'..'9', 'A'..'Z', 'a'..'z', '!', '#', # RFC 1924 for
'$', '%', '&', '(', ')', '*', '+', '-', # IPv6 addrs
';', '<', '=', '>', '?', '@', '^', '_', # like in
'`', '{', '|', '}', '~' ] # Math::Base85

If no \@newd list or digit set name is provided as a parameter, dig()
returns the current character list. It's fine to have many more
characters in your current digit set than will be used with your
conversions (e.g., using dig('b64') works fine for any cnv() call with
$from && $tobs params less than or equal to 64).

An example of a \@newd parameter for a specified alternate digit set for
base 9 conversions is:

dig( [ qw( n a c h o z y u m ) ] );

diginit()
Resets the used digit list to the initial default order of the
predefined digit set: 'b64'. This is simply a shortcut for calling
dig('b64') for reinitialization purposes.

summ($numb)
A simple function to calculate a memoized BigInt summation of $numb down
to 1.

fact($numb)
A simple function to calculate a memoized BigInt factorial of $numb.

choo($ennn, $emmm)
A simple function to calculate a memoized BigInt function of $ennn
choose $emmm.

NOTES
The Perl builtin hex() function takes a hex string as a parameter &&
returns the decimal value (FromBase = 16, ToBase = 10) but this notation
seems counter-intuitive to me since a simple reading of the code
suggests that a hex() function will turn your parameter into hexadecimal
(i.e., It sounds like Perl's hex() will hexify your parameter but it
does not.) so I've decided (maybe foolishly) to invert the notation for
my similar functions since it makes more sense to me this way && will be
easier to remember (I've had to lookup hex() in the Camel book many
times already which was part of the impetus for this module... as well
as the gut reaction that sprintf() is not a proper natural inverse
function for hex()).

This means that my b64() function takes a decimal number as a parameter
&& returns the base64 equivalent (FromBase = 10, ToBase = 64) && my
b10() function takes a base64 number (string) && returns the decimal
value (FromBase = 64, ToBase = 10). My hex() function overloads Perl's
builtin version with this opposite behavior so my dec() function behaves
like Perl's normal hex() function. I know it's confusing && maybe bad
form of me to do this but I like it so much better this way that I'd
rather go against the grain.

Please think of my dec() && hex() functions as meaning decify && hexify.
Also the pronunciation of dec() is 'dess' (!'deck' which would be the
inverse of 'ink' which -- && ++ already do so well). After reading the
informative Perl module etiquette guidelines, I now appreciate the need
to export as little as is necessary by default. So to be responsible, I
have limited BaseCnv exporting to only cnv() under normal circumstances.
Please specify the other functions you'd like to import into your
namespace or use the tags described above in the cnv() section like:

'use Math::BaseCnv qw(:all !:hex);'

Error checking is minimal.

This module does not handle fractional number inputs because I like
using the dot (.) character as a standard base64 digit since it makes
for clean filenames.

summ(), fact(), && choo() are general Math function utilities which are
unrelated to number-base conversion but I didn't feel like making
another separate module just for them so they snuck in here.

I hope you find Math::BaseCnv useful. Please feel free to e-mail me any
suggestions or coding tips or notes of appreciation
("app-ree-see-ay-shun"). Thank you. TTFN.

2DU
- better error checking
- handle fractional parts? umm but I like using '.' as a b64 char so ','
comma or some other separator?
- What else does BaseCnv need?

CHANGES
Revision history for Perl extension Math::BaseCnv:

- 1.8.B59BrZX Mon May 9 11:53:35:33 2011
* updated 'url' digit set to URLSafe to resolve
HTTPS://RT.CPAN.Org/Ticket/Display.html?id=60125

* updated license copyright years (already had GPLv3)

- 1.6.A6FGHKE Tue Jun 15 16:17:20:14 2010
* bumped minor version number so they'll keep ascending (without PT
comprehension)

- 1.4.A6FAbEb Tue Jun 15 10:37:14:37 2010
* added Math::BigInt code for >64-bit number-base conversions

* added a bunch more DigitSets: IRCu, URL, RegEx, identifier variants,
XML Nmtoken, && XML ID Name

- 1.4.75O6Pbr Thu May 24 06:25:37:53 2007
* added Test::Pod(::Coverage)? tests && PREREQ entries

* added b85 for IPv6, gen'd META.yml (w/ newline before EOF), up'd
minor ver

- 1.2.68J9uJQ Sat Aug 19 09:56:19:26 2006
* added b64sort() && put pod at bottom

- 1.2.59M7mRX Thu Sep 22 07:48:27:33 2005
* testing Make as primary and BuildPL backup (needing rename for dot)

- 1.2.59IBlgw Sun Sep 18 11:47:42:58 2005
* testing just using Module::Build instead of MakeMaker

* fixed test 12 which was failing on AMD64

* added Build.PL to pkg

- 1.2.54HK3pB Sun Apr 17 20:03:51:11 2005
* removed 128 digit-set since some hi-bit chars cause probs on Win32

* made bin/cnv only executable to go in EXE_FILES

* made Math::BaseCalc a link in pod && updated License

- 1.2.45UC8fo Sun May 30 12:08:41:50 2004
* tidied POD && upped minor version number since CPAN can't read PTVR

- 1.0.44E9ljP Wed Apr 14 09:47:45:25 2004
* added test for div-by-zero error in choo()

* added summ()

- 1.0.446EIbS Tue Apr 6 14:18:37:28 2004
* snuck in fact() && choo()

- 1.0.42REDir Fri Feb 27 14:13:44:53 2004
* changed test.pl to hopefully pass MSWin32-x86-multi-thread

- 1.0.428LV46 Sun Feb 8 21:31:04:06 2004
* broke apart CHANGES to descend chronologically

* made dec() auto uppercase param since dec(a) was returning 36
instead of 10

- 1.0.41M4GMP Thu Jan 22 04:16:22:25 2004
* put cnv in bin/ as EXE_FILES

- 1.0.418BEPc Thu Jan 8 11:14:25:38 2004
* testing new e auto-gen MANIFEST(.SKIP)?

- 1.0.3CNH37s Tue Dec 23 17:03:07:54 2003
* updated POD

- 1.0.3CG3dIx Tue Dec 16 03:39:18:59 2003
* normalized base spelling

- 1.0.3CD1Vdd Sat Dec 13 01:31:39:39 2003
* added ABSTRACT section to WriteMakeFile()

* changed synopsis example

* updated all POD indenting

- 1.0.3CCA5Mi Fri Dec 12 10:05:22:44 2003
* removed indenting from POD NAME field

- 1.0.3CB7M43 Thu Dec 11 07:22:04:03 2003
* updated package to coincide with Time::Fields release

- 1.0.39B36Lv Thu Sep 11 03:06:21:57 2003
* synchronized POD with README documentation using new e utility

* templatized package compilation

* fixed boundary bugs

- 1.0.37SLNGN Mon Jul 28 21:23:16:23 2003
* first version (&& my first Perl module... yay!) put on CPAN

- 1.0.37JKj3w Sat Jul 19 20:45:03:58 2003
* reworked interface from shell utility to package

- 1.0.3159mLT Sun Jan 5 09:48:21:29 2003
* original version

INSTALL
Please run:

`perl -MCPAN -e "install Math::BaseCnv"`

or uncompress the package && run:

`perl Makefile.PL; make; make test; make install`
or if you don't have `make` but Module::Build is installed
`perl Build.PL; perl Build; perl Build test; perl Build install`

LICENSE
Most source code should be Free! Code I have lawful authority over is &&
shall be! Copyright:(c) 2003-2011, Pip Stuart. Copyleft : This software
is licensed under the GNU General Public License (version 3). Please
consult the Free Software Foundation (HTTP://FSF.Org) for important
information about your freedom.

AUTHOR
Pip Stuart <Pip@CPAN.Org>

Math-BaseCnv-1.8.B59BrZX/bin/000075500000000000000000000000001160015652700154475ustar00rootroot00000000000000Math-BaseCnv-1.8.B59BrZX/bin/b10000064400000000000000000000004671160015652700157630ustar00rootroot00000000000000#!/usr/bin/perl
# 45UBwOb - b10 (CoNVert base-64 string parameter to decimal) as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(b10);
my $numb = shift; die("USAGE: `b10 <Base64NumberStringToConvertToDecimal>`\n") if(!defined($numb) || $numb =~ /^-+[h\?]/i); print(b10($numb));
Math-BaseCnv-1.8.B59BrZX/bin/b64000064400000000000000000000004671160015652700157740ustar00rootroot00000000000000#!/usr/bin/perl
# 45UBxJY - b64 (CoNVert decimal string parameter to base-64) as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(b64);
my $numb = shift; die("USAGE: `b64 <DecimalNumberStringToConvertToBase64>`\n") if(!defined($numb) || $numb =~ /^-+[h\?]/i); print(b64($numb));
Math-BaseCnv-1.8.B59BrZX/bin/choo000064400000000000000000000005241160015652700163230ustar00rootroot00000000000000#!/usr/bin/perl
# 43SBPRK - choo created by Pip Stuart <Pip@CPAN.Org> to calculate n choose m as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(choo);
my $ennn = shift; my $emmm = shift; die "USAGE: `choo n m` to calculate n choose m\n" unless(defined($ennn) && defined($emmm)); print choo($ennn, $emmm);
Math-BaseCnv-1.8.B59BrZX/bin/cnv000075500000000000000000000015161160015652700161660ustar00rootroot00000000000000#!/usr/bin/perl
# 315EHVb - cnv (CoNVert number bases) <NumberString> <FromBase> <ToBase> created by Pip Stuart <Pip@CPAN.Org> as part of the Math::BaseCnv package
# If you only supply a number, it will convert to hex if it's decimal && decimal if it contains only valid hex digits. If you just provide one
# base parameter, it assumes that your number is already base10 && that you've supplied the ToBase. Otherwise, you need from && to parameters.
# Examples: `cnv 127 10 16` == "7F"
# `cnv 7F 16 3` == "11201"
# `cnv 11201 3 7` == "241"
# `cnv 241 7 10` == "127" # Eror checking is minimal.
use strict; use warnings; use Math::BaseCnv;
my $numb = shift; die("USAGE: `cnv <NumberString> <FromBase> <ToBase>`\n") if(!defined($numb) || $numb =~ /^-+[h\?]/i); print(cnv($numb, shift, shift));
Math-BaseCnv-1.8.B59BrZX/bin/dec000064400000000000000000000005001160015652700161200ustar00rootroot00000000000000#!/usr/bin/perl
# 45UBsRN - dec (CoNVert hexadecimal string parameter to decimal) as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(dec);
my $numb = shift; die("USAGE: `dec <HexadecimalNumberStringToConvertToDecimal>`\n") if(!defined($numb) || $numb =~ /^-+[h\?]/i); print(dec($numb));
Math-BaseCnv-1.8.B59BrZX/bin/fact000064400000000000000000000004131160015652700163050ustar00rootroot00000000000000#!/usr/bin/perl
# 43SBKZC - fact created by Pip Stuart <Pip@CPAN.Org> to calculate factorials iteratively as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(fact); print fact(shift) || die "USAGE: `fact <NumToComputeFactorialOf>`\n";
Math-BaseCnv-1.8.B59BrZX/bin/hex000064400000000000000000000005001160015652700161510ustar00rootroot00000000000000#!/usr/bin/perl
# 45UBvZt - hex (CoNVert decimal string parameter to hexadecimal) as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(hex);
my $numb = shift; die("USAGE: `hex <DecimalNumberStringToConvertToHexadecimal>`\n") if(!defined($numb) || $numb =~ /^-+[h\?]/i); print(hex($numb));
Math-BaseCnv-1.8.B59BrZX/bin/summ000064400000000000000000000004331160015652700163530ustar00rootroot00000000000000#!/usr/bin/perl
# 446KXxq - summ created by Pip Stuart <Pip@CPAN.Org> to calculate summations down to one iteratively as part of the Math::BaseCnv package
use strict; use warnings; use Math::BaseCnv qw(summ); print summ(shift) || die "USAGE: `summ <NumToComputeSummDownToOneOf>`\n";
Math-BaseCnv-1.8.B59BrZX/ex/000075500000000000000000000000001160015652700153135ustar00rootroot00000000000000Math-BaseCnv-1.8.B59BrZX/ex/synopsis.pl000064400000000000000000000006031160015652700175360ustar00rootroot00000000000000use Math::BaseCnv;

# CoNVert 63 from base-10 (decimal) to base- 2 (binary )
$binary_63 = cnv( 63, 10, 2 );
# CoNVert 111111 from base- 2 (binary ) to base-16 (hex )
$hex_63 = cnv( 111111, 2, 16 );
# CoNVert 3F from base-16 (hex ) to base-10 (decimal)
$decimal_63 = cnv( '3F', 16, 10 );
print "63 dec->bin $binary_63 bin->hex $hex_63 hex->dec $decimal_63\n";

Math-BaseCnv-1.8.B59BrZX/t/000075500000000000000000000000001160015652700151425ustar00rootroot00000000000000Math-BaseCnv-1.8.B59BrZX/t/00pod.t000064400000000000000000000000421160015652700162450ustar00rootroot00000000000000use Test::Pod; all_pod_files_ok();Math-BaseCnv-1.8.B59BrZX/t/00podc.t000064400000000000000000000002201160015652700164060ustar00rootroot00000000000000use Test::Pod::Coverage 'tests' => '1'; pod_coverage_ok('Math::BaseCnv', { 'also_private' => [ qr/^(cnv(10)?__|bs2init$)/ ], }, 'POD Covered');
Math-BaseCnv-1.8.B59BrZX/t/01base.t000064400000000000000000000116341160015652700164070ustar00rootroot00000000000000#!/usr/bin/perl -w
# 37K2jPD - test.pl created by Pip@CPAN.Org to validate Math::BaseCnv functionality.
# This script mimics Ken Williams' <Ken@Forums.Swathmore.Edu> test cases for his Math::BaseCalc module. I have included dig() function calls with most
# tests out of respect for BaseCalc even though the only necessary calls are the ones that set the digits to something other than '0'..'9', 'A'..'Z'
# since my Math::BaseCnv diginit() function initializes the digit list with good characters for any small common number bases. My benchmarks showed
# BaseCnv to require about 3/4ths of the execution time needed by BaseCalc when including all the unnecessary dig() calls && about twice as fast when
# dig() is only called when it must be. BaseCalc may not need all the $calc->digits() calls either though so that last one is probably an unfair
# performance comparison. Besides speed, conversion functions make more sense to me than objects since I want to use them so frequently... even if
# Perl's hex() builtin is the opposite behavior of mine =).
# Before `make install' is performed this script should be run with `make test'. After `make install' it should work as `perl test.pl'.
use Math::BaseCnv qw(:all);
use Test;
my $calc; my $rslt; my $tnum = 1; my $lded = 1; my $tvrb = 0; my $tsts = 31;
END { print "not " unless($lded); print "ok $tsts\n"; }
plan('tests' => $tsts); &rprt(1);
sub rprt { # prints a rprt of test progress
my $badd = !shift();
print 'not ' if($badd);
print "ok ", $tnum++, "\n";
print @_ if(($ENV{'TEST_VERBOSE'} || $tvrb) && $badd);
}
#$calc = new Math::BaseCalc(digits=>[0,1]);
dig( [ '0', '1' ] );
$calc = 2;
&rprt($calc);
#$rslt = $calc->from_base('01101');
$rslt = cnv('01101', 2, 10);
&rprt($rslt == 13, "$rslt\n");
#$calc->digits('bin');
#$rslt = $calc->from_base('1101');
dig('bin');
$rslt = cnv('1101', 2, 10);
&rprt($rslt == 13, "$rslt\n");
#$rslt = $calc->to_base(13);
$rslt = cnv(13, 2); # omitting last param assumes first is already 10 to ?
&rprt($rslt eq '1101', "$rslt\n");
#$calc->digits('hex');
#$rslt = $calc->to_base(46);
dig('hex');
$rslt = hex(46);
&rprt($rslt eq '2e', "$rslt\n");
#$calc->digits([qw(i a m v e r y p u n k)]);
#$rslt = $calc->to_base(13933);
dig( [ qw(i a m v e r y p u n k) ] );
#$rslt = cnv(13933, 10, 11);
$rslt = cnv(13933, scalar( dig() )); # empty dig() returns the char array
&rprt($rslt eq 'krap', "$rslt\n");
#$calc->digits('hex');
#$rslt = $calc->to_base('-17');
dig('hex');
$rslt = hex(-17);
&rprt($rslt eq '-11', "$rslt\n");
#$calc->digits('hex');
#$rslt = $calc->from_base('-11');
dig('hex');
$rslt = dec(-11);
&rprt($rslt eq '-17', "$rslt\n");
# no fractions in BaseCnv! ...
# $calc->digits('hex');
# $rslt = $calc->from_base('-11.05');
# &rprt($rslt eq '-17.01953125', "$rslt\n");
# $calc->digits([0..6]);
# $rslt = $calc->from_base('0.1');
# &rprt($rslt eq (1/7), "$rslt\n");
# ... so do two more dig tests instead
dig( [ qw(i a m v e r y p u n k) ] );
$rslt = cnv(13542, scalar( dig() ));
&rprt($rslt eq 'kaka', "$rslt\n");
dig( [ qw( n a c h o z y u m ) ] );
$rslt = cnv(lc('MunchYummyNachoChz'), 9, 10) / (10**17);
$rslt = substr($rslt, 0, 10);
&rprt($rslt eq '1.46443919', "$rslt\n");
# Test large numbers && dec/hex functions
#$calc->digits('hex');
#my $r1 = $calc->to_base(2**55 + 5);
#$rslt = $calc->from_base($calc->to_base(2**55 + 5));
#warn "res: $r1, $rslt";
dig('hex');
$calc = hex(2**5 + 5);
$rslt = dec(hex(2**5 + 5));
&rprt($rslt eq (2**5 + 5), "$rslt\n");
#$calc->digits('bin');
#my $first = $calc->from_base('1110111');
#my $second = $calc->from_base('1010110');
#my $third = $calc->to_base($first * $second);
dig('bin');
my $first = cnv('1110111', 2, 10);
my $second = cnv('1010110', 2, 10);
my $third = cnv(($first * $second), 2);
&rprt($third eq '10011111111010', "$third\n");
# Test b10/b64 functions
diginit();
$rslt = b64(1234567890); # 10 base10 digits is only 6 bass64 digits
&rprt($rslt eq '19bWBI', "$rslt\n");
$rslt = b10('TheBootyBoys.com') / (10**28); # Around The Corner =)
$rslt = substr($rslt, 0, 10);
&rprt($rslt eq '3.67441470', "$rslt\n");
$rslt = b10(b64( 127));
&rprt($rslt eq '127', "$rslt\n");
$rslt = b10(b64( 4096));
&rprt($rslt eq '4096', "$rslt\n");
$rslt = b10(b64( 65535));
&rprt($rslt eq '65535', "$rslt\n");
$rslt = fact(3);
&rprt($rslt eq '6', "$rslt\n");
$rslt = fact(4);
&rprt($rslt eq '24', "$rslt\n");
$rslt = fact(7);
&rprt($rslt eq '5040', "$rslt\n");
$rslt = fact(8);
&rprt($rslt eq '40320', "$rslt\n");
$rslt = choo(7, 3);
&rprt($rslt eq '35', "$rslt\n");
$rslt = choo(15, 7);
&rprt($rslt eq '6435', "$rslt\n");
$rslt = choo(16, 8);
&rprt($rslt eq '12870', "$rslt\n");
$rslt = choo(127, 3);
&rprt($rslt eq '333375', "$rslt\n");
$rslt = summ(7);
&rprt($rslt eq '28', "$rslt\n");
$rslt = summ(8);
&rprt($rslt eq '36', "$rslt\n");
$rslt = summ(15);
&rprt($rslt eq '120', "$rslt\n");
$rslt = summ(127);
&rprt($rslt eq '8128', "$rslt\n");
 
projeto & código: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
mantenedor atual: Michael Shigorin
mantenedor da tradução: Fernando Martini aka fmartini © 2009