<p>I understand what your saying, but coming at this from the stance of a user I think it is a problem since it can greatly complicate an algorithm if you cannot pass in a negative number.</p>
<p>It is also a problem when you can't feed the output of math_eval back into itself, especially since at the script level these are stored as strings, which can't be converted to an int to check their sign. This is a problem if you would like to keep an intermediate result around, and generally just unintuitive. </p>
<pre><code> math_eval("5-7","$var(temp)");
//outputs 'Temp is : -2.000000'
xlog("Temp is : $var(temp)");
//Fails with 'cannot get left var value'
//Fails without transformation as well but instead receives 'invalid LESS_THAN operation: left is NONE/STRING_VAL, right is NUMBER/NO_VAL'
if ($(var(temp){s.int}) < 0) {
xlog("$var(temp) is negative");
}
//Will fail because $var(temp) is negative
math_eval("$var(temp) + 9", "$var(temp2)");
</code></pre>
<p>I suppose you could do a substr to get the first character and check that way, but now we are doing string operations to deal with a math problem and we have to check the sign after every subtraction. Unless you are going to remove support for subtraction, negative numbers should really be handled.</p>
<p>What are you thoughts on using something like TinyExpr from <a href="https://github.com/codeplea/tinyexpr">https://github.com/codeplea/tinyexpr</a> ?</p>
<p>It seems to handle the above cases well and even opens up for using standard C math functions in the expression as well. It also has test coverage, so it should handle potential corner cases better. It is zlib licensed, which I think is compatible? And it should be pretty easy to include.</p>
<p>If you think that looks like a reasonable solution I don't mind writing up a patch to convert the math_eval() function to use it.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/issues/788#issuecomment-184394774">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AFOciSJyD7b4tQGfCvhsy9IZlT6fGnD-ks5pkjXOgaJpZM4HYgPF.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/OpenSIPS/opensips/issues/788#issuecomment-184394774"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>