Subject: | Interpolation points not found correctly with non-integers |
Date: | Thu, 17 Sep 2009 22:38:04 +0000 (GMT) |
To: | bug-Math-Interpolator [...] rt.cpan.org |
From: | Jack Grahl <mnvl16 [...] yahoo.co.uk> |
If we try to interpolate at a point which is not an integer, currently we get either incorrect results, or we get an incorrect warning that we are trying to interpolate outside the known points when we are not
The following patch should fix this problem
--- /usr/lib/perl5/site_perl/5.8.8/Math/Interpolator.pm 2009-09-16 13:43:01.000000000 +0100
+++ Interpolator.pm 2009-09-17 23:18:14.000000000 +0100
@@ -118,8 +118,11 @@
my $max = @$self - 1;
BINSEARCH:
while($max != $min + 1) {
+ my $try;
+ {
use integer;
- my $try = ($min + $max) / 2;
+ $try = ($min + $max) / 2;
+ }
if($x >= $self->[$try]->$x_method) {
$min = $try;
} else {
As can be seen from the patch, the scope of the 'use integer' pragma is too big and encompasses the comparison operator in the 'if' condition. This leads to undesired results.
Hope this helps,
Jack Grahl