Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wishlist: some way to control output serialization #11

Open
Klortho opened this issue Apr 20, 2012 · 5 comments
Open

Wishlist: some way to control output serialization #11

Klortho opened this issue Apr 20, 2012 · 5 comments

Comments

@Klortho
Copy link
Owner

Klortho commented Apr 20, 2012

This is another to-do item from the vault.

Here's an example from a post by John Clyman on comp.languages.perl.modules (http://tinyurl.com/7hy6p4u):

  use Number::Scale;
  my $basic_si = Number::Scale->SI;
  print $basic_si->scale(1024); '1 K'
  my $si_bytes = $basic_si->new(
     unit => ['byte', 'B'],
     trunc => 2,
  );
  print $si_bytes->(1024); # '1 KB'
  my $si_distance = $basic_si->new(
     unit => ['meter', 'M'],
     trunc => 2,
  );
  my $si_weight = $basic_si->new(
     unit => ['gram', 'G'],
     trunc => 2,
  );
  my $std_distance = Number::Scale->StandardDistance;
  print $std_distance->scale(25); # '2 feet 1 inch'
  my $std_weight = Number::Scale->StandardWeight;
  print $std_weight->scale(18); # '1 pound 2 ounces'
@Klortho
Copy link
Owner Author

Klortho commented Apr 20, 2012

This would involve some way to encode systems of units. Something like this, maybe:

InitSystem (
    'si', [ qw(m kg s newton square-meter cubic-meter watt joule
               pascal m/s coulomb volt farad ohm siemens tesla weber henry)
          ],
    'cgs', [ qw(cm gm s dyne square-centimeter cubic-centimeter watt
                erg dynes-per-square-centimeter centimeters-per-second)
           ],
    'english', [ qw(foot slug s pound square-foot cubic-foot horsepower
                    foot-pound pounds-per-square-inch feet-per-second)
               ],
);

@jberger
Copy link
Collaborator

jberger commented Apr 20, 2012

A few things to note, your first system is not SI, but rather MKS. SI uses grams not kilograms. I think that if this was a goal, it would fit in with having loadable databases per instance. One would make a Physics::Unit object, load a units database and set the units system. I think this is a worthy goal, but a major undertaking.

@Klortho
Copy link
Owner Author

Klortho commented Apr 22, 2012

your first system is not SI, but rather MKS

According to Wikipedia, it is kilograms.

Another system that we'll definitely want support for is the Furlong/Firkin/Fortnight (FFF) system. :)

@jberger
Copy link
Collaborator

jberger commented Apr 22, 2012

Well I stand corrected, NIST

@Klortho
Copy link
Owner Author

Klortho commented Apr 30, 2012

There are other very good ways to specify output serialization.

Here's how Math::Units::PhysicalValue does it:

print ($rate + "0 miles/hour"), "\n" # prints 103.07 miles/hour

Another would be a method to produce an output using the best SI prefix. Quoting jpierce on RT: "Since you already have prefix to exponent mapping, it would be mighty handy to have a method of taking a result like 1.055056e+18 (joules) and getting back: 1.055056, exa(joules)."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants