Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

math::calc::units(3pm) [debian man page]

Units(3pm)						User Contributed Perl Documentation						Units(3pm)

NAME
Math::Calc::Units - Human-readable unit-aware calculator SYNOPSIS
use Math::Calc::Units qw(calc readable convert equal); print "It will take ".calc("10MB/(384Kbps)")." to download "; my @alternative_descriptions = readable("10MB/(384Kbps)"); print "A week is ".convert("1 week", "seconds")." long "; if (equal("$rate bytes / sec", "1 MB/sec")) { ... }; DESCRIPTION
"Math::Calc::Units" is a simple calculator that keeps track of units. It currently handles combinations of byte sizes and duration only, although adding any other multiplicative types is easy. Any unknown type is treated as a unique user type (with some effort to map English plurals to their singular forms). The primary intended use is via the "ucalc" script that prints out all of the "readable" variants of a value. For example, "3 bytes" will only produce "3 byte", but "3 byte / sec" produces the original along with "180 byte / minute", "10.55 kilobyte / hour", etc. The "Math::Calc::Units" interface only provides for string-based computations, which could result in a large loss of precision for some applications. If you need the exact result, you may pass in an extra parameter 'exact' to "calc" or "convert", causing them to return a 2-element list containing the numerical result and a string describing the units of that result: my ($value, $units) = convert("10MB/sec", "GB/day"); (In scalar context, they just return the numeric value.) Examples of use o Estimate transmission rates (e.g., 10MB at 384 kilobit/sec) o Estimate performance characteristics (e.g., disk I/O rates) o Figure out how long something will take to complete I tend to work on performance-sensitive code that involves a lot of network and disk traffic, so I wrote this tool after I became very sick of constantly converting KB/sec to GB/day when trying to figure out how long a run is going to take, or what the theoretical maximum performance would be if we were 100% disk bound. Now I can't live without it. Contraindications If you are just trying to convert from one unit to another, you'll probably be better off with "Math::Units" or "Convert::Units". This module really only makes sense when you're converting to and from human-readable values. AUTHOR
Steve Fink <sfink@cpan.org> SEE ALSO
ucalc, Math::Units, Convert::Units. perl v5.10.0 2009-08-04 Units(3pm)

Check Out this Related Man Page

Math::BaseCalc(3pm)					User Contributed Perl Documentation				       Math::BaseCalc(3pm)

NAME
Math::BaseCalc - Convert numbers between various bases VERSION
version 1.016 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
o new Math::BaseCalc o 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). If your digit set includes the character "-", then a dash at the beginning of a number will no longer signify a negative number. o $calc->to_base(NUMBER) Converts a number to a string representing that number in the associated base. If "NUMBER" is a "Math::BigInt" object, "to_base()" will still work fine and give you an exact result string. o $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. If "STRING" converts to a number too large for perl's integer representation, beware that the result may be auto-converted to a floating-point representation and thus only be an approximation. o $calc->digits o $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@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). perl v5.12.3 2011-05-16 Math::BaseCalc(3pm)
Man Page