DateTime-Util-Calc
view release on metacpan or search on metacpan
lib/DateTime/Util/Calc.pm view on Meta::CPAN
These have been deprecated.
=head2 truncate_to_midday($dt)
Truncates the DateTime object to 12:00 noon.
=head2 sin_deg($degrees)
=head2 cos_deg($degrees)
=head2 tan_deg($degrees)
=head2 asin_deg($degrees)
=head2 acos_deg($degrees)
Each of these functions calculates their respective values based on degrees,
not radians (as Perl's version of sin() and cos() would do).
=head2 mod($v,$mod)
Calculates the modulus of $v over $mod. Perl's built-in modulus operator (%)
for some reason rounds numbers UP when a fractional number's modulus is
taken. Many of the calculations also needed the fractional part of the
calculation, so this function takes care of both.
Example:
mod(12.234, 5) = 2.234
=head2 amod($v,$mod)
This function is almost identical to mod(), but when the regular modulus value
is 0, returns $mod instead of 0.
Example:
amod(11, 5) = 1
amod(10, 5) = 5
amod(9, 5) = 4
amod(8, 5) = 3
=head2 binary_search($hi, $lo, $mu, $phi)
This is a special version of binary search, where the terminating condition
is determined by the result of coderefs $mu and $phi.
$mu is passed the value of $hi and $lo. If it returns true upon execution,
then the search terminates.
$phi is passed the next median value. If it returns true upon execution,
then the search terminates.
If the above two fails, then $hi and $lo are re-computed for the next
iteration.
=head2 search_next(%opts)
Performs a "linear" search until some condition is met. This is a generalized
version of the formula defined in [1] p.22. The basic idea is :
x = base
while (! check(x) ) {
x = next(x);
}
return x
%opts can contain the following parameters:
=over 4
=item base
The initial value to use to start the search process. The value can be
anything, but you must provide C<check> and C<next> parameters that are
capable of handling the type of thing you specified.
=item check (coderef)
Code to be executed to determine the end of the search. The function receives
the current value of "x", and should return a true value if the condition
to end the loop has been reached
=item next (coderef, optional)
Code to be executed to determine the next value of "x". The function receives
the current value of "x", and should return the value to be used for the
next iteration.
If unspecified, it will use a function that blindly adds 1 to whatever x is.
(so if you specified a number for C<base>, it should work -- but if you
passed an object like DateTime, it will probably be an error)
=back
So for example, to iterate through 1 through 9, you could do something
like this
my $x = search_next(
base => 1,
check => sub { $_[0] == 9 }
);
And $x will be set to 9. For a more interesting example, we could look
for a DateTime object $dt matching a certain condition C<foo()>:
my $dt = search_next(
base => $base_date,
check => \&foo,
next => sub { $_[0] + DateTime::Duration->new(days => 1) }
);
=head2 deg2rad
Converts degrees to radians using Math::Trig, but works for Math::BigInt
objects as well.
=head2 revolution($angle_in_degrees)
Reduces any angle to within the first revolution by sbtracting or adding
( run in 0.606 second using v1.01-cache-2.11-cpan-df04353d9ac )