[Avida-SVN] r1447 - trunk/source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Apr 2 05:34:56 PDT 2007


Author: brysonda
Date: 2007-04-02 08:34:56 -0400 (Mon, 02 Apr 2007)
New Revision: 1447

Modified:
   trunk/source/main/cPopulation.cc
Log:
Back port fixes to cPopulation negative-zero wonkiness (in the technical sense).

Modified: trunk/source/main/cPopulation.cc
===================================================================
--- trunk/source/main/cPopulation.cc	2007-04-02 12:30:01 UTC (rev 1446)
+++ trunk/source/main/cPopulation.cc	2007-04-02 12:34:56 UTC (rev 1447)
@@ -1278,8 +1278,11 @@
     stats.SumSize().Add(cur_genotype->GetLength(), abundance);
     
     // Calculate this genotype's contribution to entropy
+    // - when p = 1.0, partial_ent calculation would return -0.0. This may propagate
+    //   to the output stage, but behavior is dependent on compiler used and optimization
+    //   level.  For consistent output, ensures that 0.0 is returned.
     const double p = ((double) abundance) / (double) num_organisms;
-    const double partial_ent = -(p * Log(p));
+    const double partial_ent = (p == 1.0) ? 0.0 : -(p * Log(p)); 
     entropy += partial_ent;
     
     // Do any special calculations for threshold genotypes.
@@ -1329,9 +1332,12 @@
     stats.SumSpeciesAge().Add(species_age, abundance);
     
     // Caculate entropy on the species level...
+    // - when p = 1.0, partial_ent calculation would return -0.0. This may propagate
+    //   to the output stage, but behavior is dependent on compiler used and optimization
+    //   level.  For consistent output, ensures that 0.0 is returned.
     if (abundance > 0) {
       double p = ((double) abundance) / (double) num_organisms;
-      double partial_ent = -(p * Log(p));
+      double partial_ent = (p == 1.0) ? 0.0 : -(p * Log(p));
       species_entropy += partial_ent;
     }
     




More information about the Avida-cvs mailing list