Added MIN and MAX functions for operand.

This commit is contained in:
Brad Arant 2025-11-24 12:15:56 -08:00
parent c21f27f14d
commit 3314a410e0
2 changed files with 66 additions and 2 deletions

View File

@ -146,9 +146,63 @@ namespace jet {
} else
throw coreutils::Exception("Expecting ) at end of ABS expression.");
} else if(in.ifNextIgnoreCase("MAX")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for MAX parameters.");
Operand *parm = new Operand(in, tag);
string = parm->string;
doubleValue = parm->doubleValue;
isNumber = parm->isNumber;
delete parm;
while(in.ifNext(",")) {
parm = new Operand(in, tag);
if(isNumber != parm->isNumber)
throw coreutils::Exception("All parameters in MAX expression must be same type.");
if(isNumber) {
if(parm->doubleValue > doubleValue) {
doubleValue = parm->doubleValue;
string = parm->string;
}
} else {
if(parm->string > string) {
doubleValue = parm->doubleValue;
string = parm->string;
}
}
delete parm;
}
if(!in.ifNext(")")) {
throw coreutils::Exception("Expecting ) at end of MAX expression.");
}
string.removeTrailingZeros();
} else if(in.ifNextIgnoreCase("MIN")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for MIN parameters.");
Operand *parm = new Operand(in, tag);
string = parm->string;
doubleValue = parm->doubleValue;
isNumber = parm->isNumber;
delete parm;
while(in.ifNext(",")) {
parm = new Operand(in, tag);
if(isNumber != parm->isNumber)
throw coreutils::Exception("All parameters in MIN expression must be same type.");
if(isNumber) {
if(parm->doubleValue < doubleValue) {
doubleValue = parm->doubleValue;
string = parm->string;
}
} else {
if(parm->string < string) {
doubleValue = parm->doubleValue;
string = parm->string;
}
}
delete parm;
}
if(!in.ifNext(")")) {
throw coreutils::Exception("Expecting ) at end of MIN expression.");
}
string.removeTrailingZeros();
} else if(in.ifNextIgnoreCase("POW")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for POW parameters.");

View File

@ -64,9 +64,19 @@
</for>
<call error="rc" pgm="/usr/bin/ls" arg1="-al" name="ls" />
$[rc]
<set name="max" expr="max(1, 2, 3, 4, 5, 4, 3, 2, 1)" />
max=$[max]
<set name="max" expr="max('A', 'B', 'C', 'D', 'E', 'D', 'C', 'B', 'A')" />
max=$[max]
<set name="min" expr="min(1, 2, 3, 4, 5, 4, 3, 2, 1)" />
min=$[min]
<set name="min" expr="min('A', 'B', 'C', 'D', 'E', 'D', 'C', 'B', 'A')" />
min=$[min]
<comment>
$[ls]
<read file="../compile" name="file" />
$[file]
</comment>
<comment>
<whiledir path="/var/www" filename="file" fullpath="fullpath" filenamenoextension="noext" sort="true">
$[file] $[fullpath] $[noext]