Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the GIS-Distance-Fast CPAN distribution.

Report information
The Basics
Id: 46502
Status: resolved
Priority: 0/
Queue: GIS-Distance-Fast

People
Owner: Nobody in particular
Requestors: john.engelhart [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug in (at least) Vincenty calculation
Date: Fri, 29 May 2009 23:01:18 -0400
To: bug-GIS-Distance-Fast [...] rt.cpan.org
From: John Engelhart <john.engelhart [...] gmail.com>
Hello, There is a bug in "GIS-Distance-Fast-0.02/lib/GIS/Distance/Formula/Vincenty/Fast.pm", line 88: while( abs(lambda-lambda_pi) > 1e-12 && --iter_limit>0 ){ The problem is with the use of 'abs()'. abs() takes an int for an argument and returns an int value (ie, works with int types, not double types). To get the desired behavior, you need to use 'fabs()', which accepts and returns double values. Because of the use of abs(), which converts the difference to an int, the while() body effectively never iterates because the int type is unable to represent the required precision. A few, completely random tests would seem to indicate that after the first iteration, the difference is ~ > 0.001, so the abs((int)(lambda-lambda_pi)) Show quoted text
> 1e-12 check is always true. :(
Also, I'd recommend using the math.h / C[89]9 standard definition for pi, M_PI. For my platform, M_PI is 3.14159265358979323846264338327950288, which is of greater precision than the supplied PI value of 3.14159265358979323846. A third recommendation is to turn all the integer constants in the source to double constants (ie, 256 becomes 256.0). Using integer constant values technically means something very slightly different according to the C standard, so it's just good form to be explicit about it.
Hello - sorry for the long delay in a reply. I've updated the module to include all of the changes you suggested which I think are great. I'm neither a C programmer nor a mathematician, so the slight difference this makes in the Vincenty results looks "ok" to me. :) Thanks tons, Aran On Fri May 29 23:01:48 2009, john.engelhart@gmail.com wrote: Show quoted text
> Hello, > There is a bug in > "GIS-Distance-Fast-0.02/lib/GIS/Distance/Formula/Vincenty/Fast.pm",
line 88: Show quoted text
> > while( abs(lambda-lambda_pi) > 1e-12 && --iter_limit>0 ){ > > The problem is with the use of 'abs()'. abs() takes an int for an
argument Show quoted text
> and returns an int value (ie, works with int types, not double types). To > get the desired behavior, you need to use 'fabs()', which accepts and > returns double values. Because of the use of abs(), which converts the > difference to an int, the while() body effectively never iterates because > the int type is unable to represent the required precision. A few, > completely random tests would seem to indicate that after the first > iteration, the difference is ~ > 0.001, so the
abs((int)(lambda-lambda_pi)) Show quoted text
> > 1e-12 check is always true. :(
> > Also, I'd recommend using the math.h / C[89]9 standard definition for pi, > M_PI. For my platform, M_PI is 3.14159265358979323846264338327950288,
which Show quoted text
> is of greater precision than the supplied PI value > of 3.14159265358979323846. > > A third recommendation is to turn all the integer constants in the
source to Show quoted text
> double constants (ie, 256 becomes 256.0). Using integer constant values > technically means something very slightly different according to the C > standard, so it's just good form to be explicit about it.