Units(3)
π¦ Units(3) β Math::Calc::Units π¦
okay bestie, welcome to the User Contributed Perl Documentation page for the unit-aware calculator thatβs here to make your conversions make sense π
β¨ NAME β¨
Math::Calc::Units - Human-readable unit-aware calculator, periodt. π
π SYNOPSIS π
okay so hereβs the group-chat demo:
use Math::Calc::Units qw(calc readable convert equal);
print "It will take ".calc("10MB/(384Kbps)")." to download\n";
my @alternative_descriptions = readable("10MB/(384Kbps)");
print "A week is ".convert("1 week", "seconds")." long\n";
if (equal("$rate bytes / sec", "1 MB/sec")) { ... };
π DESCRIPTION π
Math::Calc::Units is a simple calculator that keeps track of units, no cap. 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 πΈ
- Estimate transmission rates (e.g., 10MB at 384 kilobit/sec)
- Estimate performance characteristics (e.g., disk I/O rates)
- 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 π
bestie, real talk: if you are just trying to convert from one unit to another, you'll probably be better off withMath::UnitsorConvert::Units. This module really only makes sense when you're converting to and from human-readable values. π
π AUTHOR π
Steve Fink <sfink@cpan.org> β the icon behind this whole unit-aware situation π«Ά
π SEE ALSO π
ucalcMath::UnitsConvert::Units
mwah π β this page is signing off from the perl v5.42.0 source/version era, dated 2013-01-15, with all the Units(3) love π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Math-Calc-Units 1.07-bp160.1.8 Β· Artistic-1.0
- opensuse-leap 16.0: perl-Math-Calc-Units 1.07-bp160.1.8 Β· Artistic-1.0
- opensuse-leap 16.0: perl-Math-Calc-Units 1.07-bp160.1.8 Β· Artistic-1.0
- opensuse-leap 16.0: perl-Math-Calc-Units 1.07-bp160.1.8 Β· Artistic-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms