The whole issue of floating point precision has been answered, but you're still seeing the problem despite bignum
. Why? The culprit is printf
. bignum
is a shallow pragma. It only affects how numbers are represented in variables and math operations. Even though bignum
makes Perl do the math right, printf
is still implemented in C. %f
takes your precise number and turns it right back into an imprecise floating point number.
Print your numbers with just print
and they should do fine. You'll have to format them manually.
The other thing you can do is to recompile Perl with -Duse64bitint -Duselongdouble
which will force Perl to internally use 64 bit integers and long double
floating point numbers. This will give you a lot more accuracy, more consistently and almost no performance cost (bignum
is a bit of a performance hog for math intensive code). Its not 100% accurate like bignum
, but it will affect things like printf
. However, recompiling Perl this way makes it binary incompatible, so you're going to have to recompile all your extensions. If you do this, I suggest installing a fresh Perl in a different location (/usr/local/perl/64bit
or something) rather than trying to manage parallel Perl installs sharing the same library.