WFL: Cleanup of min() and max() function, and allow them to work on strings etc
It was already possibly for them to work on strings by using a list, but this is more consistent.
This commit is contained in:
parent
94e73a7ccc
commit
eccd3d8e7e
1 changed files with 20 additions and 30 deletions
|
@ -200,22 +200,17 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
||||||
bool found = false;
|
variant res = args()[0]->evaluate(variables, fdb);
|
||||||
variant res(0);
|
if(res.is_list()) {
|
||||||
for(size_t n = 0; n != args().size(); ++n) {
|
res = *std::min_element(res.begin(), res.end());
|
||||||
const variant v = args()[n]->evaluate(variables,fdb);
|
}
|
||||||
|
for(size_t n = 1; n < args().size(); ++n) {
|
||||||
|
variant v = args()[n]->evaluate(variables,fdb);
|
||||||
if(v.is_list()) {
|
if(v.is_list()) {
|
||||||
for(size_t m = 0; m != v.num_elements(); ++m) {
|
v = *std::min_element(v.begin(), v.end());
|
||||||
if(!found || v[m] < res) {
|
}
|
||||||
res = v[m];
|
if(res.is_null() || v < res) {
|
||||||
found = true;
|
res = v;
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(v.is_int() || v.is_decimal()) {
|
|
||||||
if(!found || v < res) {
|
|
||||||
res = v;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,22 +226,17 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
variant execute(const formula_callable& variables, formula_debugger *fdb) const {
|
||||||
bool found = false;
|
variant res = args()[0]->evaluate(variables, fdb);
|
||||||
variant res(0);
|
if(res.is_list()) {
|
||||||
for(size_t n = 0; n != args().size(); ++n) {
|
res = *std::max_element(res.begin(), res.end());
|
||||||
const variant v = args()[n]->evaluate(variables,fdb);
|
}
|
||||||
|
for(size_t n = 1; n < args().size(); ++n) {
|
||||||
|
variant v = args()[n]->evaluate(variables, fdb);
|
||||||
if(v.is_list()) {
|
if(v.is_list()) {
|
||||||
for(size_t m = 0; m != v.num_elements(); ++m) {
|
v = *std::max_element(v.begin(), v.end());
|
||||||
if(!found || v[m] > res) {
|
}
|
||||||
res = v[m];
|
if(res.is_null() || v > res) {
|
||||||
found = true;
|
res = v;
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if(v.is_int() || v.is_decimal()) {
|
|
||||||
if(!found || v > res) {
|
|
||||||
res = v;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue