Skip to content

Commit 031dc9e

Browse files
committedJul 19, 2015
Fix calculation/stack, breaks op pushing
1 parent 971627a commit 031dc9e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
 

‎src/main.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int perform_op(tricalc_op op, double a, double b, double* result) {
9696
arity = 1;
9797
break;
9898
default:
99-
return 0;
99+
return 0;
100100
}
101101

102102
return arity;
@@ -110,27 +110,31 @@ static void action_commit(struct tricalc_click_context* clickcontext) {
110110
}
111111
if (clickcontext->long_click) {
112112
tricalc_op op = get_op_for_button(clickcontext);
113-
double b = (double) atoi(accumulator_string); //strtod(accumulator_string, NULL);
114-
double a = 0;
113+
double a = (double) atoi(accumulator_string); //strtod(accumulator_string, NULL);
114+
double b = 0;
115115
double result = 0;
116116
int arity = 0;
117117
tricalc_op_stack_entry* item = tricalc_op_stack_peek(&stack);
118-
a = item ? item->val : b;
118+
b = item ? item->val : a;
119+
APP_LOG(APP_LOG_LEVEL_DEBUG, "items %d", stack.items );
119120

120121
arity = perform_op(op, a, b, &result);
121122
if (arity == 2) {
122123
tricalc_op_stack_pop_value(&stack, NULL);
123124
}
125+
APP_LOG(APP_LOG_LEVEL_DEBUG, "items2 %d", stack.items );
124126

125127
if (arity != 0) {
126-
tricalc_op_stack_push(&stack, result, op, a, b);
128+
if (op == OP_ENTER)
129+
tricalc_op_stack_push(&stack, result, op, a, b);
127130
/*XXX: Pebble snprintf doesn't support any float printing functions!*/
128131
/*TODO: Do this properly (ugh)*/
129132
snprintf(accumulator_string, sizeof(accumulator_string), "%d.%03d", (int) result, (int)((int64_t)(result*1000) % 1000));
130133
//reset accumulator so next input works correctly
131134
accumulator_string_offset = 0;
132135
}
133136
}
137+
APP_LOG(APP_LOG_LEVEL_DEBUG, "items3 %d", stack.items );
134138
text_layer_set_text(op_text_layer, "");
135139
}
136140

‎src/op_stack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
bool tricalc_op_stack_push(tricalc_op_stack* stack, double result, tricalc_op op, double a, double b) {
55
tricalc_op_stack_entry* item = NULL;
66

7-
if (stack && stack->items > 0 && stack->items < TRICALC_OP_STACK_LEN)
7+
if (stack && stack->items < TRICALC_OP_STACK_LEN)
88
{
99
item = &stack->head[stack->items];
1010
item->val = result;

0 commit comments

Comments
 (0)