Open yarcod opened 1 year ago
no, it's not you... this fixes it:
diff --git a/toys/pending/expr.c b/toys/pending/expr.c
index a236aaab..54ebd14b 100644
--- a/toys/pending/expr.c
+++ b/toys/pending/expr.c
@@ -146,9 +146,8 @@ static struct op_def {
void eval_op(struct op_def *o, struct value *ret, struct value *rhs)
{
- long long a, b, x = 0; // x = a OP b for ints.
+ long long cmp, a, b, x = 0; // x = a OP b for ints.
char *s, *t; // string operands
- int cmp;
switch (o->sig) {
but i think rob's rewriting expr right now anyway?
Great, thanks! Does this also solve the issue with the inconsistent return codes? Because I am still not sure what they were caused by.
Commit 251be88968c1 with a test.
As for rewrite, I have a tree with a dirty expr.c in it but it doesn't collapse cleanly into the $(( )) math logic and I find a lot of its string vs not string behavior non-obvious, so I keep waffling over throw it out vs patch what's there vs try not to touch it...
Doing some small testing on an Android phone, I noticed that arithmetic operations seem to work as expected, i.e. they use 64 bits, but comparisons seems to only use 32 bits. This means that while a number larger than 2^31 plus another number would work, but comparing those two will give an different result.
To give some examples:
That last example did not throw any error, and that is erroneous from what I can tell.
I am not able to determine exactly when
expr
returns an error, because it does not always seem to be due to overflows. So, I have two issues to report, perhaps. Both the inconsistent use of 32 and 64 bit integers in comparisons and arithmetic, as well as inconsistent errors being thrown when comparing large numbers.Or am I just missing something? :)