-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(-1)^0 returns -1 instead of 1 #52
Comments
Interesting. It seems to only happen with |
When Without There are probably other cases such as I will try to work up a solution soon. |
I've added some extra test cases to |
@Photosounder Same issue raised here: #10 (comment) |
Doesn't matter to me anymore, I've made a more sophisticated replacement for TinyExpr https://github.com/Photosounder/rouziclib#expression-parsing 😁 |
Very nice 👍 |
I think the problem can only be handled correctly by introducing another precedence level for the unary minus (and plus) sign, as it is be done by regular C expression parsers in the compiler, too. |
When I evaluate
(-1)^0
I get -1, which is wrong. Yet when I evaluatepow(-1, 0)
I get 1, which is correct. It seems to be an expression compilation error since te_eval only runscase TE_CONSTANT: return n->value;
.(-x)^0
also always yields -1 regardless of the value of x, whilex^0
and(0-x)^0
correctly yield 1. I'm using the logic branch in case that matters, withTE_POW_FROM_RIGHT
defined.Btw for the ease of debugging I suggest that you name your tokens enum, something like
enum token
and useenum token type;
instead ofint type;
in thestate
struct, this way debuggers will show the name of the enum.The text was updated successfully, but these errors were encountered: