Subject: | fib series() rounding |
Date: | Sun, 13 Jun 2010 07:49:10 +1000 |
To: | bug-Math-Fibonacci [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
With Math::Fibonacci 1.5 on recent 32-bit i386 debian perl 5.10.1, a
program
use strict;
use warnings;
use Math::Fibonacci 'series';
my @fib = series(70);
foreach my $i (59 .. 61) {
printf ("%2d %16s\n", $i, $fib[$i]);
}
prints
59 1548008755920
60 2504730781961
61 4052739537880
Where I expected the last number to be 4052739537881, the sum of the
previous two.
Those values are about 40-something bits, so they're still exactly
representable in a 53-bit double and I hoped Math::Fibonacci would give
exact values up to the point they can be represented.
Perhaps simple additions in series() would maintain exactness up to
53-bits, and even to 64-bits on a 64-bit UV system.