[Avida-SVN] r2056 - trunk/source/tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Sep 6 08:48:07 PDT 2007
Author: brysonda
Date: 2007-09-06 11:48:07 -0400 (Thu, 06 Sep 2007)
New Revision: 2056
Modified:
trunk/source/tools/cMerit.cc
trunk/source/tools/cMerit.h
Log:
Port cMerit fixes from development into trunk.
Modified: trunk/source/tools/cMerit.cc
===================================================================
--- trunk/source/tools/cMerit.cc 2007-09-06 15:30:17 UTC (rev 2055)
+++ trunk/source/tools/cMerit.cc 2007-09-06 15:48:07 UTC (rev 2056)
@@ -15,23 +15,19 @@
void cMerit::UpdateValue(double in_value)
{
- const int max_bits = sizeof(unsigned int)*8;
- static double mult[max_bits];
- static bool mult_initilalized = false;
+ static const int max_bits = sizeof(unsigned int) * 8;
+ struct sExponentMultiplier
+ {
+ double mult[max_bits + 1];
+ sExponentMultiplier() { for (int i = 0; i <= max_bits; i++) mult[i] = pow(2.0, i - 1); }
+ };
+ static sExponentMultiplier exp;
- // Do not allow negative merits. If less than 1, set to 0.
+
+ // Do not allow negative merits. If less than 1, set to 0.
if (in_value < 1.0) in_value = 0.0;
- // Initilize multipliers only once
- if( mult_initilalized == false ){
- mult_initilalized = true;
- for( int i=0; i<max_bits; ++i ){
- mult[i] = pow((double)2,i);
- }
- }
-
value = in_value;
-
double mant = frexp (value , &bits);
if( bits > max_bits ){
@@ -40,7 +36,7 @@
offset = 0;
}
- base = (unsigned int) (mant * mult[bits-offset-1] * 2 );
+ base = static_cast<unsigned int>(mant * exp.mult[bits - offset] * 2.0);
}
Modified: trunk/source/tools/cMerit.h
===================================================================
--- trunk/source/tools/cMerit.h 2007-09-06 15:30:17 UTC (rev 2055)
+++ trunk/source/tools/cMerit.h 2007-09-06 15:48:07 UTC (rev 2056)
@@ -78,7 +78,7 @@
double CalcFitness(int gestation_time) const {
return ( gestation_time != 0 ) ? value / ((double) gestation_time) : 0; }
- std::ostream& BinaryPrint(std::ostream& os = std::cout) const ;
+ std::ostream& BinaryPrint(std::ostream& os = std::cout) const;
};
More information about the Avida-cvs
mailing list