Quote:
> Scaling and the SI prefix application are both tied together insofar as the
> goal is to make numbers with units associated presentable in a more
> human-friendly fashion. The typical application is where you are reporting
> on some number whose values can span multiple orders of magnitude and would
> like a nice way to package up the description, i.e.:
> $converter->scale(1); # '1 byte'
> $converter->scale(2); # '2 bytes'
> $converter->scale(1024); # '1 KB'
> $converter->scale(7**8); # '5.5 MB'
> ...instead of the usual "5764801 bytes" that you'd see in the last case.
> So perhaps something like Number::PrettyUnits would describe that...
Yes, perhaps that's better.
I like "scale" or "prefix" better than "unit". As a Physics major,
"unit" reminds me of "Unit of measure" which was meter, foot, gram,
amp, etc. When someone asked me what units that measurement was in, I
could answer feet, inches, meters, or fathoms.
Byte is *not* an SI base unit, nor is it a derived one. It is merely
another name for a thing like rock, or bird, and should be (IMHO)
separated from the scaling of the count.
If you'd like more information on SI units, look at the NIST site for
Constants, Units and Uncertainty
http://physics.nist.gov/cuu/Units/
http://physics.nist.gov/cuu/Units/units.html
Please don't invoke an international standard by name (i.e. SI) if you
aren't really implementing it. To do so would cause a confusion for
your module users now, and in the future, and block the namespace for
someone who wanted to do so.
Here's a bit from the first page I referenced. These *are* SI units.
Base quantity Name Symbol
length meter m
mass kilogram kg
time second s
electric current ampere A
thermodynamic temperature kelvin K
amount of substance mole mol
luminous intensity candela cd
The page goes on to talk about derivative units like velocity,
acceleration, area, volume.
And it discusses scaling, and newly minted binary multiple prefixes.
Perhaps that would be helpful to you.
http://physics.nist.gov/cuu/Units/prefixes.html
http://physics.nist.gov/cuu/Units/binary.html
Be careful. By which I mean, please provide good documentation. "M"
can mean 1,000 or 1024 in common usage. I'd suggest that you provide
both, and have a different interface to them. See the
"--human-readable" and "--si" argument to du(1) to note the
difference. I'm sure other tools implement this numbering/naming. If
you provide a useful module, it would be useful in the Perl world for
doing similar helpful output. I'd love it if you did. And it would
be nice to comma-ify the output, too. I've cut the section of the
du(1) man(1) page here:
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si
likewise, but use powers of 1000 not 1024
So again, I'm lead back to my original suggestion that units and
sacaling are separate problems, and would be served by *separate*
modules.
This whole thread reminds me of fun handout we got in Physics class.
I remember 2 of them.
2,000 mockingbirds => two kilo mockingbird
10E-18 boy => atto boy
...
more playfulness???
================================================================
Table 5. SI prefixes
Factor Name Symbol
10E+24 yotta Y
10E+21 zetta Z
10E+18 exa E
10E+15 peta P
10E+12 tera T
10E+9 giga G
10E+6 mega M
10E+3 kilo k
10E+2 hecto h
10E+1 deka da
10E-1 deci d
10E-2 centi c
10E-3 milli m
10E-6 micro
10E-9 nano n
10E-12 pico p
10E-15 femto f
10E-18 atto a
10E-21 zepto z
10E-24 yocto y
================================================================
Prefixes for binary multiples
Factor Name Symbol Origin Derivation
2**10 kibi Ki kilobinary: (2**10)**1 kilo: (10**3)**1
2**20 mebi Mi megabinary: (2**10)**2 mega: (10**3)**2
2**30 gibi Gi gigabinary: (2**10)**3 giga: (10**3)**3
2**40 tebi Ti terabinary: (2**10)**4 tera: (10**3)**4
2**50 pebi Pi petabinary: (2**10)**5 peta: (10**3)**5
2**60 exbi Ei exabinary: (2**10)**6 exa: (10**3)**6
Examples and comparisons with SI prefixes
one kibibit 1 Kibit = 210 bit = 1024 bit
one kilobit 1 kbit = 103 bit = 1000 bit
one mebibyte 1 MiB = 220 B = 1 048 576 B
one megabyte 1 MB = 106 B = 1 000 000 B
one gibibyte 1 GiB = 230 B = 1 073 741 824 B
one gigabyte 1 GB = 109 B = 1 000 000 000 B
I like the idea. I think it would be *very* helpful. I really don't
like seeing lists of long numbers. This module would go a long way to
helping folks make better output. But it's got the possibility of
being confusing, so I offered my feedback.
Hope this is taken in the spirit it was offerred -- helpfulness.
Michael Wolf
Quote:
> --John
> > > I have a small module that a couple of folks have asked me to post to
> CPAN,
> > > and I'd like to get suggestions on an appropriate name. The module lets
> you
> > > instantiate objects that will scale numbers and apply appropriate SI
> > > prefixes. Simple example:
> > [...]
> > > Thoughts, comments?
> > Shooting from the hip ----
> > Which is more important, the scale or the SI? Had you considered
> > Number::SI
> > Units::SI
> > Unit::SI
> > Does the scale part belong with the SI part, or can they be reasonably
> > factored into two modules that play well together?
> > --
> > Michael R. Wolf
> > All mammals learn by playing!
--
Michael R. Wolf
All mammals learn by playing!