ECF 1.5
Div.h
1#ifndef Div_h
2#define Div_h
3#include <cmath>
4#include "Primitive.h"
5
6namespace Tree {
7namespace Primitives {
8
9const double MIN = 0.000000001; // protected division parameter
10
15template <class T>
16class DivT : public Primitive
17{
18public:
19 DivT(void);
20 void execute(void* result, Tree& tree);
21 ~DivT(void);
22};
23typedef DivT<double> Div;
24
25
26template <class T>
27DivT<T>::DivT(void)
28{
29 nArguments_ = 2;
30 name_ = "/";
31 complementName_ = "*";
32}
33
34
35template <class T>
36DivT<T>::~DivT(void)
37{ }
38
39
40template <class T>
41void DivT<T>::execute(void* result, Tree &tree)
42{
43 T first, second;
44 T& division = *(T*)result;
45 getNextArgument(&first, tree);
46 getNextArgument(&second, tree);
47
48 // T must be auto castable to double!
49 division = fabs(second) > MIN ? first / second : 1.;
50}
51
52}
53}
54
55#endif
Div function primitive (Tree genotype)
Definition: Div.h:17
void execute(void *result, Tree &tree)
Execute the primitive.
Definition: Div.h:41
Base primitive class (Tree genotype).
Definition: Primitive.h:37
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29