DateTime-Util-Calc

 view release on metacpan or  search on metacpan

lib/DateTime/Util/Calc.pm  view on Meta::CPAN

    # any angle
    #
    # _THEN
    #
    # reduces any angle to within the first revolution 
    # by subtracting or adding even multiples of 360.0
    # 
    #
    # _RETURN
    #
    # the value of the input is >= 0.0 and < 360.0
    #

    my $x = $_[0];
    return ( $x - 360.0 * POSIX::floor( $x * ( 1.0 / 360.0 ) ) );
}

sub rev180
{
    #
    #
    # FUNCTIONAL SEQUENCE for rev180
    #
    # _GIVEN
    # 
    # any angle
    #
    # _THEN
    #
    # Reduce input to within +180..+180 degrees
    # 
    #
    # _RETURN
    #
    # angle that was reduced
    #
    my ($x) = @_;
    return ( $x - 360.0 * POSIX::floor( $x * ( 1.0 / 360.0 ) + 0.5 ) );
}


1;

__END__

=head1 NAME

DateTime::Util::Calc - DateTime Calculation Utilities

=head1 SYNOPSIS

  use DateTime::Util::Calc qw(polynomial);

  my @coeffs = qw(2 3 -2);
  my $x      = 5;
  my $rv     = polynomial($x, @coeffs);

=head1 DEPRECATION WARNING

You really should not be using this module. Math::BigInt nad friends are fine,
but they are not realistic for anything more complicated... like calendars.
If you need an astronomical calendar, use C (and/or provide a very thing
Perl wrapper over it)

Because the author has reached the above conclusion, this module should really
be considered deprecated. It will NOT be maintained regularly.

=head1 DESCRIPTION

This module contains some common calculation utilities that are required
to perform datetime calculations, specifically from "Calendrical Calculations"
-- they are NOT meant to be general purpose.

Nothing is exported by default. You must either explicitly export them,
or use as fully qualified function names.

=head1 FUNCTIONS

=head2 max($a, $b)

=head2 min($a, $b)

max() returns the bigger of $a and $b. min() returns the smaller of $a and $b.

=head2 polynomial($x, @coefs)

Calculates the value of a polynomial equation, based on Horner's Rule.

   c + b * x + a * (x ** 2)     x = 5

is expressed as:

   polynomial(5, c, b, a);

=head2 moment($dt)

=head2 dt_from_moment($moment)

moment() converts a DateTime object to moment, which is RD days + the time 
of day as fraction of the total seconds in a day.

dt_from_moment() converts a moment to DateTime object.

=head2 rata_die()

Returns a new DateTime object that is set to Rata Die, 0001-01-01 00:00:00 UTC

=head2 bigfloat($v)

=head2 bigint($v)

If the value $v is not a Math::BigFloat object, returns the value converted
to Math::BigFloat. Otherwise returns the value itself.

bigint() does the same for Math::BigInt.

=head2 bf_downgrade($v)

=head2 bi_downgrade($v)

These have been deprecated.



( run in 2.036 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )