summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@gmail.com>2011-01-04 22:15:53 -0800
committerTom Stellard <tstellar@gmail.com>2011-01-04 22:15:53 -0800
commitd7be2c024ed9bd61416c1c8546276fe0189cb92a (patch)
treee7edcea093c7b399ab0e103d44025d1abd22ebd4
parent034b517e572a926d3593834f9fff79207c9b61b0 (diff)
Add max_instruction
-rw-r--r--evaluator.cpp17
-rw-r--r--evaluator.h8
-rw-r--r--instruction.cpp4
-rw-r--r--instruction.h5
4 files changed, 34 insertions, 0 deletions
diff --git a/evaluator.cpp b/evaluator.cpp
index eccf579..4b264af 100644
--- a/evaluator.cpp
+++ b/evaluator.cpp
@@ -220,3 +220,20 @@ min_evaluator::evaluate(
return new float_value(
l->m_value < r->m_value ? l->m_value : r->m_value);
}
+
+max_evaluator::max_evaluator() :
+ evaluator("MAX")
+ { }
+
+value *
+max_evaluator::evaluate(
+ float_value * l,
+ float_value * r)
+{
+ if (!l || !l->m_has_value || !r || !r->m_has_value) {
+ return default_evaluate(l, r);
+ }
+
+ return new float_value(
+ l->m_value > r->m_value ? l->m_value : r->m_value);
+}
diff --git a/evaluator.h b/evaluator.h
index a5ee018..15f95d8 100644
--- a/evaluator.h
+++ b/evaluator.h
@@ -89,4 +89,12 @@ public:
float_value * r);
};
+class max_evaluator : public evaluator {
+public:
+ max_evaluator();
+ value * evaluate(
+ float_value * l,
+ float_value * r);
+};
+
#endif //EVALUATOR_H_
diff --git a/instruction.cpp b/instruction.cpp
index 93682e8..8febec0 100644
--- a/instruction.cpp
+++ b/instruction.cpp
@@ -135,3 +135,7 @@ rcp_instruction::rcp_instruction(std::vector<register_address> dst) :
min_instruction::min_instruction(std::vector<register_address> dst) :
instruction("MIN", new min_evaluator(), dst, 2)
{ }
+
+max_instruction::max_instruction(std::vector<register_address> dst) :
+ instruction("MAX", new max_evaluator(), dst, 2)
+ { }
diff --git a/instruction.h b/instruction.h
index d0775f8..e200845 100644
--- a/instruction.h
+++ b/instruction.h
@@ -88,4 +88,9 @@ public:
min_instruction(std::vector<register_address> dst);
};
+class max_instruction : public instruction {
+public:
+ max_instruction(std::vector<register_address> dst);
+};
+
#endif //INSTRUCTION_H_