Made behavior of Math abs, min and max more consistent with the standard.

git-svn-id: http://yate.null.ro/svn/yate/trunk@6471 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2021-03-29 10:34:12 +00:00
parent ef15153c1f
commit b482039d8a
1 changed files with 8 additions and 8 deletions

View File

@ -1636,22 +1636,20 @@ bool JsMath::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
XDebug(DebugAll,"JsMath::runNative() '%s' in '%s' [%p]",
oper.name().c_str(),toString().c_str(),this);
if (oper.name() == YSTRING("abs")) {
if (!oper.number())
return false;
int64_t n = 0;
int64_t n = ExpOperation::nonInteger();
for (int i = (int)oper.number(); i; i--) {
ExpOperation* op = popValue(stack,context);
if (op->isInteger())
n = op->number();
else if (JsParser::isEmpty(*op))
n = 0;
TelEngine::destruct(op);
}
if (n < 0)
if ((ExpOperation::nonInteger() != n) && (n < 0))
n = -n;
ExpEvaluator::pushOne(stack,new ExpOperation(n));
}
else if (oper.name() == YSTRING("max")) {
if (!oper.number())
return false;
int64_t n = LLONG_MIN;
for (int i = (int)oper.number(); i; i--) {
ExpOperation* op = popValue(stack,context);
@ -1659,11 +1657,11 @@ bool JsMath::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
n = op->number();
TelEngine::destruct(op);
}
if (LLONG_MIN == n)
n = ExpOperation::nonInteger();
ExpEvaluator::pushOne(stack,new ExpOperation(n));
}
else if (oper.name() == YSTRING("min")) {
if (!oper.number())
return false;
int64_t n = LLONG_MAX;
for (int i = (int)oper.number(); i; i--) {
ExpOperation* op = popValue(stack,context);
@ -1671,6 +1669,8 @@ bool JsMath::runNative(ObjList& stack, const ExpOperation& oper, GenObject* cont
n = op->number();
TelEngine::destruct(op);
}
if (LLONG_MAX == n)
n = ExpOperation::nonInteger();
ExpEvaluator::pushOne(stack,new ExpOperation(n));
}
else if (oper.name() == YSTRING("random")) {