RFC: Module Physics::Measurement

Discussion in 'Perl Misc' started by John, May 7, 2004.

  1. John

    John Guest

    Physics::Measurement is a subclass of Physics::Unit::Scalar, but with
    overloaded operators. Like it's superclass, the module allows the creation
    of objects that represent physical quantities with encapsulated dimensions;
    but Physics::Measurment objects provide some nifty features

    I'm looking for input from the list: What do you think? Do we need it on
    CPAN? Is it apty named? Other comments?

    Features of Physics::Measurement objects
    -Overloaded arithmetic and inequality operators
    -Dies on operations on two measurments with incompatible quantities. So
    you can't add 1 foot to 1 second, although you can divide 1 foot by 1
    second.
    -Automaticly stringified when interpolated into a string.
    -Produces warning when used in a string comparison (cmp, gt, etc).
    Otherwise things like
    "2 minutes" lt new Physics::Measurement("40 seconds");
    will cause hard-to-find bugs.
    -Dies when used in numeric comparison with non-measurements. So you can't
    compare "3 ounces" to 12.
    -Automatically converts strings to measurements, when a measurement and a
    string are used in a numeric operation:
    (new Measurement("3 meters")) + "1 meter" == "4 meter"
    -Always true in boolean expressions (in contrast to regular numbers, where
    0 is false).
    -(Not yet implemented) Significant figures and scientific notation.
    I would like to use the Math::SigFigs module to handle this.

    Examples

    #Overloaded arithmetic and inequality operators
    my $distance = new Physics::Measurement("3.0e8 m");
    my $time = new Physics::Measurement("1 s");

    my $speed = $distance / $time;
    my $warp10 = $speed*10;

    #Automatic stringification
    print "Warp 10 is: $warp10\n";

    ###String comparison with strings produces warning.
    if(1*meter gt "1 yard"); #Will compare the string "1 m" to "1 yard", and
    produces false and a warning.

    #Incomperable to other numbers
    my $m = new Physics::Measurement("5 m");

    $m + 10; #All these raise an exception
    $m == 5; #...
    $m < 10; #...
    log($m) #...

    #Numeric comparison with strings does automatic upgrade
    my $speed = new Physics::measurement("60 mph");
    $speed == "1 mile/minute"; #True.
    $speed == "blah blah"; #Tries to parse blah blah and dies.
    1*meter > "1 yard"; #True

    ###boolean always true
    my $m = new Physics::Measurement('0 m');
    $m and $m; #True...
    John, May 7, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Floyd Pepper

    Re: REQ: Physics Java Class

    Floyd Pepper, Jul 30, 2003, in forum: Java
    Replies:
    2
    Views:
    453
    Floyd Pepper
    Jul 31, 2003
  2. Floyd Pepper
    Replies:
    0
    Views:
    730
    Floyd Pepper
    Sep 14, 2003
  3. Petr Aubrecht

    Physics simulation framework

    Petr Aubrecht, Jul 12, 2004, in forum: Java
    Replies:
    1
    Views:
    606
    TechBookReport
    Jul 13, 2004
  4. Satish Chimakurthi

    Python and Multi-Physics

    Satish Chimakurthi, Mar 3, 2004, in forum: Python
    Replies:
    2
    Views:
    440
    Fernando Perez
    Mar 3, 2004
  5. Ivan Shmakov
    Replies:
    3
    Views:
    1,125
    Kari Hurtta
    Feb 13, 2012
Loading...

Share This Page