Skip to content

Commit

Permalink
rename digit operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrause committed Jan 5, 2025
1 parent 59be6d3 commit 96d80e2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ To install or update LODA, please follow the [installation instructions](https:/

## [Unreleased]

### Enhancements

* Rename digit operations

## v25.1.3

### Bugfixes
Expand Down
8 changes: 4 additions & 4 deletions src/eval/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ Number Interpreter::calc(const Operation::Type type, const Number& target,
case Operation::Type::NRT: {
return Semantics::nrt(target, source);
}
case Operation::Type::DIS: {
return Semantics::dis(target, source);
case Operation::Type::DGS: {
return Semantics::dgs(target, source);
}
case Operation::Type::DIR: {
return Semantics::dir(target, source);
case Operation::Type::DGR: {
return Semantics::dgr(target, source);
}
case Operation::Type::EQU: {
return Semantics::equ(target, source);
Expand Down
4 changes: 2 additions & 2 deletions src/eval/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Number Semantics::nrt(const Number& a, const Number& b) {
return r;
}

Number Semantics::dis(const Number& a, const Number& b) {
Number Semantics::dgs(const Number& a, const Number& b) {
if (a == Number::INF || b == Number::INF || b < Number::TWO) {
return Number::INF;
}
Expand All @@ -237,7 +237,7 @@ Number Semantics::dis(const Number& a, const Number& b) {
return mul(sign, r);
}

Number Semantics::dir(const Number& a, const Number& b) {
Number Semantics::dgr(const Number& a, const Number& b) {
if (a == Number::INF || b == Number::INF || b < Number::TWO) {
return Number::INF;
}
Expand Down
4 changes: 2 additions & 2 deletions src/eval/semantics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class Semantics {

static Number nrt(const Number& a, const Number& b);

static Number dis(const Number& a, const Number& b);
static Number dgs(const Number& a, const Number& b);

static Number dir(const Number& a, const Number& b);
static Number dgr(const Number& a, const Number& b);

static Number equ(const Number& a, const Number& b);

Expand Down
27 changes: 17 additions & 10 deletions src/lang/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const std::array<Operation::Type, 33> Operation::Types = {
Operation::Type::DIV, Operation::Type::DIF, Operation::Type::MOD,
Operation::Type::POW, Operation::Type::GCD, Operation::Type::LEX,
Operation::Type::BIN, Operation::Type::LOG, Operation::Type::NRT,
Operation::Type::DIS, Operation::Type::DIR, Operation::Type::EQU,
Operation::Type::DGS, Operation::Type::DGR, Operation::Type::EQU,
Operation::Type::NEQ, Operation::Type::LEQ, Operation::Type::GEQ,
Operation::Type::MIN, Operation::Type::MAX, Operation::Type::BAN,
Operation::Type::BOR, Operation::Type::BXO, Operation::Type::LPB,
Expand Down Expand Up @@ -47,10 +47,10 @@ const Operation::Metadata& Operation::Metadata::get(Type t) {
Operation::Type::LOG, "log", 2, true, true, true};
static Operation::Metadata nrt{
Operation::Type::NRT, "nrt", 2, true, true, true};
static Operation::Metadata dis{
Operation::Type::DIS, "dis", 2, true, true, true};
static Operation::Metadata dir{
Operation::Type::DIR, "dir", 2, true, true, true};
static Operation::Metadata dgs{
Operation::Type::DGS, "dgs", 2, true, true, true};
static Operation::Metadata dgr{
Operation::Type::DGR, "dgr", 2, true, true, true};
static Operation::Metadata equ{
Operation::Type::EQU, "equ", 2, true, true, true};
static Operation::Metadata neq{
Expand Down Expand Up @@ -114,10 +114,10 @@ const Operation::Metadata& Operation::Metadata::get(Type t) {
return log;
case Operation::Type::NRT:
return nrt;
case Operation::Type::DIS:
return dis;
case Operation::Type::DIR:
return dir;
case Operation::Type::DGS:
return dgs;
case Operation::Type::DGR:
return dgr;
case Operation::Type::EQU:
return equ;
case Operation::Type::NEQ:
Expand Down Expand Up @@ -163,9 +163,16 @@ const Operation::Metadata& Operation::Metadata::get(const std::string& name) {
return m;
}
}
if (name == "cmp") { // backwards compatibility
// for backwards compatibility
if (name == "cmp") {
return get(Operation::Type::EQU);
}
if (name == "dis") {
return get(Operation::Type::DGS);
}
if (name == "dir") {
return get(Operation::Type::DGR);
}
throw std::runtime_error("invalid operation: " + name);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lang/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Operation {
BIN, // binomial coefficient
LOG, // logarithm
NRT, // n-th root
DIS, // digit sum
DIR, // digital root
DGS, // digit sum
DGR, // digital root
EQU, // equality
NEQ, // inequality
LEQ, // less or equal
Expand Down
8 changes: 4 additions & 4 deletions src/mine/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ bool Iterator::inc(Operation& op) {
return true;

case Operation::Type::BIN:
op.type = Operation::Type::DIS;
op.type = Operation::Type::DGS;
return true;

case Operation::Type::DIS:
op.type = Operation::Type::DIR;
case Operation::Type::DGS:
op.type = Operation::Type::DGR;
return true;

case Operation::Type::DIR:
case Operation::Type::DGR:
op.type = Operation::Type::EQU;
return true;

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 96d80e2

Please sign in to comment.