HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/share/perl5/Math/Calc/Units/Convert.pm
package Math::Calc::Units::Convert;
use base 'Exporter';
use strict;
use vars qw(@EXPORT_OK);
BEGIN { @EXPORT_OK = qw(convert reduce canonical find_top construct); };

use Math::Calc::Units::Convert::Multi qw(to_canonical);

# convert : value x unit -> value
#
# The lower-level conversion routines really only know how to convert
# things to canonical units. But this routine may be called with eg
# 120 minutes -> hours. So we convert both the current and target to
# canonical units, and divide the first by the second. (Doesn't work
# for adding units that aren't multiples of each other, but that's not
# what this tool is for anyway.)
sub convert {
    my ($from, $unit) = @_;

    my $to = [ 1, $unit ];

    my $canon_from = canonical($from);
    my $canon_to = canonical($to);

    die "conversion between incompatible units"
      if not same_units($canon_from->[1], $canon_to->[1]);

    return [ $canon_from->[0] / $canon_to->[0], $unit ];
}

# Are the (canonical) units compatible? (They must have exactly the
# same base units, and each must be raised to exactly the same power.)
sub same_units {
    my ($u1, $u2) = @_;
    return if keys %$u1 != keys %$u2;
    while (my ($bu1, $bp1) = each %$u1) {
        return if ! exists $u2->{$bu1};
        return if $bp1 != $u2->{$bu1};
    }
    return 1;
}

sub canonical {
    my ($v) = @_;
    my $c = to_canonical($v->[1]);
    my $w = [ $v->[0] * $c->[0], $c->[1] ];
    return $w;
}

sub reduce {
    my ($v) = @_;
    return canonical($v, 'reduce, please');
}

sub construct {
    my ($constructor, $args) = @_;
    return Math::Calc::Units::Convert::Multi::construct($constructor, $args);
}

1;