[Avida-SVN] r1190 - development/source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Jan 15 04:28:31 PST 2007


Author: brysonda
Date: 2007-01-15 07:28:31 -0500 (Mon, 15 Jan 2007)
New Revision: 1190

Modified:
   development/source/main/cTaskLib.cc
   development/source/main/cTaskLib.h
Log:
Adjust trig tasks to use double in order to reduce overflow potential.  Remove tangent task, as there are too many exceptions to reasonably handle.

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2007-01-14 03:52:43 UTC (rev 1189)
+++ development/source/main/cTaskLib.cc	2007-01-15 12:28:31 UTC (rev 1190)
@@ -20,7 +20,7 @@
 #include <limits.h>
 
 
-static const float fCastPrecision = 10000.0f;
+static const double dCastPrecision = 100000.0;
 
 
 cTaskLib::~cTaskLib()
@@ -340,8 +340,6 @@
     Load_Sine(name, info, envreqs, errors);
   else if (name == "cosine")
     Load_Cosine(name, info, envreqs, errors);
-  else if (name == "tangent")
-    Load_Tangent(name, info, envreqs, errors);
 
   
   // Communication Tasks
@@ -2375,7 +2373,7 @@
   int diff = INT_MAX;
   
   for (int i = 0; i < input_size; i ++) {
-    int cur_diff = abs(static_cast<int>(sinf(static_cast<float>(input_buffer[i]) / fCastPrecision) * fCastPrecision) - test_output);
+    int cur_diff = abs(static_cast<int>(sin(static_cast<double>(input_buffer[i]) / dCastPrecision) * dCastPrecision) - test_output);
     if (cur_diff < diff) diff = cur_diff;
   }
   
@@ -2416,7 +2414,7 @@
   int diff = INT_MAX;
   
   for (int i = 0; i < input_size; i ++) {
-    int cur_diff = abs(static_cast<int>(cosf(static_cast<float>(input_buffer[i]) / fCastPrecision) * fCastPrecision) - test_output);
+    int cur_diff = abs(static_cast<int>(cos(static_cast<double>(input_buffer[i]) / dCastPrecision) * dCastPrecision) - test_output);
     if (cur_diff < diff) diff = cur_diff;
   }
   
@@ -2432,51 +2430,9 @@
 }
 
 
-void cTaskLib::Load_Tangent(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
-{
-  cArgSchema schema;
-  
-  // Integer Arguments
-  schema.AddEntry("threshold", 0, -1);
-  // Double Arguments
-  schema.AddEntry("halflife", 0, cArgSchema::SCHEMA_DOUBLE);
-  
-  cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
-  if (args) NewTask(name, "Tangent", &cTaskLib::Task_Tangent, 0, args);
-}
 
-double cTaskLib::Task_Tangent(cTaskContext& ctx) const
-{
-  double quality = 0.0;
-  const cArgContainer& args = ctx.GetTaskEntry()->GetArguments();
-  
-  const tBuffer<int>& input_buffer = ctx.GetInputBuffer();
-  const int test_output = ctx.GetOutputBuffer()[0];
-  const int input_size = input_buffer.GetNumStored();
-  
-  int diff = INT_MAX;
-  
-  for (int i = 0; i < input_size; i ++) {
-    int cur_diff = abs(static_cast<int>(tanf(static_cast<float>(input_buffer[i]) / fCastPrecision) * fCastPrecision) - test_output);
-    if (cur_diff < diff) diff = cur_diff;
-  }
-  
-  int threshold = args.GetInt(0);
-  
-  if (threshold < 0 || diff <= threshold) { // Negative threshold == infinite
-                                            // If within threshold range, quality decays based on absolute difference
-    double halflife = -1.0 * fabs(args.GetDouble(0));
-    quality = pow(2.0, static_cast<double>(diff) / halflife);
-  }
-  
-  return quality;
-}
 
 
-
-
-
-
 double cTaskLib::Task_CommEcho(cTaskContext& ctx) const
 {
   const int test_output = ctx.GetOutputBuffer()[0];

Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h	2007-01-14 03:52:43 UTC (rev 1189)
+++ development/source/main/cTaskLib.h	2007-01-15 12:28:31 UTC (rev 1190)
@@ -247,8 +247,6 @@
   double Task_Sine(cTaskContext& ctx) const;
   void Load_Cosine(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
   double Task_Cosine(cTaskContext& ctx) const;
-  void Load_Tangent(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
-  double Task_Tangent(cTaskContext& ctx) const;
 
 
   // Communication Tasks




More information about the Avida-cvs mailing list