Data::Dimensions

Data::Dimensions is a Perl module used to strongly type values with physical units.
Download

Data::Dimensions Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Alex Gough
  • Publisher web site:
  • http://search.cpan.org/~ajgough/Data-Dimensions-0.04/lib/Data/Dimensions.pm

Data::Dimensions Tags


Data::Dimensions Description

Data::Dimensions is a Perl module used to strongly type values with physical units. Data::Dimensions is a Perl module with strongly type values with physical units.SYNOPSIS use Data::Dimensions qw(extended &units); my $energy = Data::Dimensions->new( {joule => 1} ); # or, more simply... my $mass = units( {kg =>1 } ); my $c = units( {m=>1, s=>-1} ); $mass->set = 10; $c->set = 299_792_458; # checks that units of mc^2 same as energy, use indirect syntax... set $energy = $mass * $c**2; # made a mistake on right, so dies with error set $energy = $mass * $c**3;Careful with that Equation, EugeneIn many applications type checking will make code more robust as algorithmic (rather than syntax) errors can be found automatically. Most languages which implement a type system (eg. C) only go as far as giving each variable or function a single type property (such as int frobnicate(int x, float y)) which can be a user defined type (a C typedef). This system is useful but falls short of the typing needed in many applications, for instance it cannot catch the following error (again, in C): PENCE_PER_GALLON unit_price; VOLUME volume; PENCE price; price = volume / unit_price;Instead we want unit_price to have a type of pence per gallon, volume a type of gallons and price a type of pence. We also want these types to propogate through expressions so that the resulting type of volume / unit_price is gallons / ( pence / gallons ) == gallons ** 2 / pencewhich is clearly not of the same type as price which we can detect and therefore issue an appropriate error message.Many scientific applications also require strong typing of this form, for instance the famous equation E == M * C**2 is such that the type (or units) of Energy (Joule) is identical to the units of Mass (kg) times the units of the speed of light (m/s) squared, this provides an indication that the equation is correct, and if we were to use it as part of a calculation in a program, we can use the units of the quantities to ensure that we have entered our program correctly.It is also important to note that in many cases two quantities will have different units but are used to measure the same underlying property of something. For instance, the metric meter and the Imperial foot both measure the length of an object. As an example, the volume of wood in a thin plank could be calculated given: $length in yards $width in feet $depth in inches $volume in cubic feetWe could calculate our volume by carefully converting all the measurements to have the same units (inches, say) but this introduces large amounts of code into our application which isn't crucial to the problem we are attempting to solve (and that's a bad thing, remember). Instead if our variables are all typed, we can get them to perform automatic conversion between different units, so that $volume = $length * $width * $depth;is all we need to say. Requirements: · Perl


Data::Dimensions Related Software