Subject: | conversion of angle between -1 and 0 |
Date: | Thu, 02 Nov 2006 12:40:48 +0100 |
To: | bug-Geo-Coordinates-DecimalDegrees [...] rt.cpan.org |
From: | Tim Flohrer <tim.flohrer [...] aiub.unibe.ch> |
Dear Walter,
it appears that there is an error in Geo-Coordinates-DecimalDegrees in
version 0.05.
I am using perl v5.8.7 built for x86_64-linux-thread-multi on a "Linux
aiuli1 2.6.13-15.10-smp #1 SMP Fri May 12 16:11:24 UTC 2006 x86_64
x86_64 x86_64 GNU/Linux".
Consider the following:
perl -e 'use Geo::Coordinates::DecimalDegrees; printf("%d %d
%f\n",decimal2dms(-0.987))'
gives:
0 59 13.200000
which is wrong.
Of course, the following:
perl -e 'use Geo::Coordinates::DecimalDegrees; printf("%d %d
%f\n",decimal2dms(-1.987))'
returning:
-1 59 13.20000
is correct.
I guess, a possible fix would be to include the sign of the angle in the
returned data explicitly and to require the user to handle this like
"$deg*=-1 if($sign)", if i.e. decimal2dms reads like:
sub decimal2dms {
my ($decimal) = @_;
$sign='';
$sign='-' if ($decimal<0.);
$decimal=abs($decimal);
my $degrees = int($decimal);
# convert decimal part to minutes
my $dec_min = abs($decimal - $degrees) * 60;
my $minutes = int($dec_min);
my $seconds = ($dec_min - $minutes) * 60;
return ($sign, $degrees, $minutes, $seconds);
}
Best regards,
Tim
--
Show quoted text
________________________________________________________________________
Tim Flohrer eMail: tim.flohrer@aiub.unibe.ch
Astronomical Institute www: http://www.aiub.unibe.ch/
University of Bern
Sidlerstrasse 5 Phone: +41-31-631 38 92
CH-3012 Bern, Switzerland Fax: +41-31-631 38 69
________________________________________________________________________