From b482039d8a402253fc8f6509021d6d5deab7517f Mon Sep 17 00:00:00 2001 From: paulc Date: Mon, 29 Mar 2021 10:34:12 +0000 Subject: [PATCH] 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 --- libs/yscript/jsobjects.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/yscript/jsobjects.cpp b/libs/yscript/jsobjects.cpp index 3d7df3fa..b205ba4a 100644 --- a/libs/yscript/jsobjects.cpp +++ b/libs/yscript/jsobjects.cpp @@ -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")) {