On Oct 30, 2009, at 2:04 PM, Bill Bogstad wrote:
So I have this perl program that does things like calculate averages, standard deviations, and normalizes some data. I'm running it under Ubuntu 8.04 (fully updated) using the stock perl installation for that OS. I'm doing this on two different machines (both using Core 2 duo CPUs (but not identical chips). I believe the only other significant difference between the two machines is that one of them is running 32-bit Ubuntu and the other is running 64-bit. Running the same perl program with the same data in those two different environments generates slightly different results. Okay, I understand that floating point math isn't precise etc., etc. However....
It would help to see a subset of the input.
I wondered if there is someway to make the differences go away and stumbled across "perl -Mbignum". Doing so doesn't seem to change my results on the two machines let alone make them identical. Am I doing something wrong here? I don't plan to run under bignum in general, but it would be nice to know how to use it just in case....
If you just use bignum, you are accepting defaults which are probably different for different Perl installations. You'd get better control over what is happening if you use Math::BigFloat objects and functions directly. It will require a fair amount of rewriting of your program, though.
A halfway measure is to use the a or p options to bignum. "perl - Mbignum=a,50 scriptname" should maintain 50 digits of accuracy through all arithmetic functions. It looks like sqrt() is covered (so std dev should be okay), but you'll need to verify any other functions you are using in the normalizations. Bignum is a significant performance hit, of course.
It's been a long time since my Numerical Methods course, but there are techniques for maintaining maximum accuracy through your math, even with limited precision floats. For averages, for example, do all the additions, then one division, instead of dividing each datapoint before adding. "Numerical Recipes in C" used to be the standard text.
--kag _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

