expr
expr copied to clipboard
Possible issue with calculation
code:= 1+1/(4+5)*(1*5)+3.3+3.3+3.3+3.3/3.3*3.3
When I run this code in excel, I get 14.7555. When I run it in expr, I get 14.2.
What accounts for the difference?
however this works:
1.0+1/(4.0+5)*(1*5.0)+3.3+3.3+3.3+3.3/3.3*3.3
yields
14.7555
It looks like you have to marshal the integers into floats by adding .0
Thank you.
I think this can be an issue: 1/(4+5)*(1*5)
How do you propose this can be solved? At the code level or at the end consumer level by adding the .0 hint to a literal numerator or denominator when there is division? However, if both the numerator and denominator are both integer variables then we may have less control.
What about float as default for every constants in 1/2 expression?
What about float as default for every constants in 1/2 expression?
I think this will work. Float as a default for all division operations is a excellent rational solution to this issue as this will cover integer variables as numerators or denominators also and not just constants/literals.
@davidklassen what do you think?
There is another issue related to precedence, I don't know if it is the same root cause. The expression "-(1*2)^2" it is expected "-4" but it was returned "4".
The expression "-(1*2)^2" it is expected "-4" but it was returned "4".
The correct answer is 4.
Not according to google and wolfram alpha =p
https://www.wolframalpha.com/input/?i=-%2812%29%5E2 https://letmegooglethat.com/?q=-(12)%5E2
I guess unary op is higher priority than exponential in expr.
Fixed in https://github.com/antonmedv/expr/commit/2aec311b2bcdb9ab5a8efee88c08138dde84a65c