I am working with latitudes and longitudes to determine business locations and ran into some odd behavior.
In the Perl snippet below, the equation assigning data to $v1 evaluates to 1. When I call acos($v1), I receive a sqrt error. When I call acos("$v1") (with quotes), I do not. Calling acos(1) does not produce the error, either. Why do the quotes matter?
use strict;
use warnings 'all';
sub acos {
my $rad = shift;
return (atan2(sqrt(1 - $rad**2), $rad));
}
my $v1 = (0.520371764072297 * 0.520371764072297) +
(0.853939826425894 * 0.853939826425894 * 1);
print acos($v1); # Can't take sqrt of -8.88178e-16 at foo line 8.
print acos("$v1"); # 0