Macroprocessor: implement power operator for integers
For consistency with the power operator for sets (see #5).issue#70
parent
a35c1785a8
commit
4624a3104d
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "MacroDriver.hh"
|
#include "MacroDriver.hh"
|
||||||
|
|
||||||
|
@ -198,6 +199,15 @@ IntMV::divide(const MacroValuePtr &mv) noexcept(false)
|
||||||
return make_shared<IntMV>(value / mv2->value);
|
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>
|
shared_ptr<IntMV>
|
||||||
IntMV::is_less(const MacroValuePtr &mv) noexcept(false)
|
IntMV::is_less(const MacroValuePtr &mv) noexcept(false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,6 +135,7 @@ public:
|
||||||
MacroValuePtr times(const MacroValuePtr &mv) noexcept(false) override;
|
MacroValuePtr times(const MacroValuePtr &mv) noexcept(false) override;
|
||||||
//! Computes arithmetic division
|
//! Computes arithmetic division
|
||||||
MacroValuePtr divide(const MacroValuePtr &mv) noexcept(false) override;
|
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_less(const MacroValuePtr &mv) noexcept(false) override;
|
||||||
shared_ptr<IntMV> is_greater(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;
|
shared_ptr<IntMV> is_less_equal(const MacroValuePtr &mv) noexcept(false) override;
|
||||||
|
|
Loading…
Reference in New Issue