Macroprocessor: implement power operator for integers

For consistency with the power operator for sets (see #5).
issue#70
Sébastien Villemot 2018-09-04 16:28:38 +02:00
parent a35c1785a8
commit 4624a3104d
2 changed files with 11 additions and 0 deletions

View File

@ -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)
{

View File

@ -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;