diff --git a/Operand.cpp b/Operand.cpp index b250e23..af8bee7 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -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."); diff --git a/tests/testjet.jet b/tests/testjet.jet index 974334c..1c4b4c8 100755 --- a/tests/testjet.jet +++ b/tests/testjet.jet @@ -64,9 +64,19 @@ $[rc] + + max=$[max] + + max=$[max] + + min=$[min] + + min=$[min] + $[ls] $[file] + $[file] $[fullpath] $[noext]