Michael G Schwern wrote:
>4) .7216 seconds is 43 microseconds

No it's bloody not.  It's 43 *thirds*, but no one ever uses thirds
of time.  Even thirds of angle have long fallen out of use, in favour
of decimal fractions of the second.  .7216 seconds is 721600 microseconds.

>I'm moving a bunch of stuff.  I have X time to do it in.  I need to make Y
>trips.  How fast will each trip have to be?

To answer this kind of question, you don't want calendar durations,
you want interval time.  You want units of *time*, not calendar units.
DateTime::Duration is capable of representing this, in the form of an
interval of seconds and nanoseconds only.  (Modulo DateTime's multiple
personality regarding which kind of second it's using.)  I think DateTime
ought to make this type of interval more accessible.  DT:D also claims
to be capable of multiplying such an interval by a scalar, but it gets
this wrong:

        use DateTime;   # *bug* DT:D fails if this isn't loaded first
        use DateTime::Duration;

        $d = DateTime::Duration->new(nanoseconds=>123456789012);
        print $d->delta_seconds, ".", $d->delta_nanoseconds, "\n";
        # => 123.456789012

        $d *= 2;
        print $d->delta_seconds, ".", $d->delta_nanoseconds, "\n";
        # => 246.913578024

        $d *= 0.5;
        print $d->delta_seconds, ".", $d->delta_nanoseconds, "\n";
        # => 123.456789012

        $d *= 0.5;
        print $d->delta_seconds, ".", $d->delta_nanoseconds, "\n";
        # => 61.228394506
        # *bug* it's lost the half that needs to carry into the ns

        $d *= 2;
        print $d->delta_seconds, ".", $d->delta_nanoseconds, "\n";
        # => 122.456789012
        # correctly multiplied up from previous, shows the lost second

There, you've got two outright bugs to be getting on with.

-zefram

Reply via email to