Commit 4624a310 authored by Sébastien Villemot's avatar Sébastien Villemot

Macroprocessor: implement power operator for integers

For consistency with the power operator for sets (see #5).
parent a35c1785
......@@ -18,6 +18,7 @@
*/
#include <utility>
#include <cmath>
#include "MacroDriver.hh"
......@@ -198,6 +199,15 @@ IntMV::divide(const MacroValuePtr &mv) noexcept(false)
return make_shared<IntMV>(value / mv2->value);
}
MacroValuePtr
IntMV::power(const MacroValuePtr &mv) noexcept(false)
{
auto mv2 = dynamic_pointer_cast<IntMV>(mv);
if (!mv2)
throw TypeError("Type mismatch for operands of ^ operator");
return make_shared<IntMV>(pow(value, mv2->value));
}
shared_ptr<IntMV>
IntMV::is_less(const MacroValuePtr &mv) noexcept(false)
{
......
......@@ -135,6 +135,7 @@ public:
MacroValuePtr times(const MacroValuePtr &mv) noexcept(false) override;
//! Computes arithmetic division
MacroValuePtr divide(const MacroValuePtr &mv) noexcept(false) override;
MacroValuePtr power(const MacroValuePtr &mv) noexcept(false) override;
shared_ptr<IntMV> is_less(const MacroValuePtr &mv) noexcept(false) override;
shared_ptr<IntMV> is_greater(const MacroValuePtr &mv) noexcept(false) override;
shared_ptr<IntMV> is_less_equal(const MacroValuePtr &mv) noexcept(false) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment