diff --git a/src/vm.c b/src/vm.c index e2c5e3b0..16b04bea 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1,5 +1,6 @@ #include #include +#include #include "picrin.h" #include "picrin/pair.h" @@ -418,7 +419,13 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv) b = POP(); \ a = POP(); \ if (pic_int_p(a) && pic_int_p(b)) { \ - PUSH(pic_int_value(pic_int(a) op pic_int(b))); \ + double f = (double)pic_int(a) op (double)pic_int(b); \ + if (INT_MIN <= f && f <= INT_MAX) { \ + PUSH(pic_int_value((int)f)); \ + } \ + else { \ + PUSH(pic_float_value(f)); \ + } \ } \ else if (pic_float_p(a) && pic_float_p(b)) { \ PUSH(pic_float_value(pic_float(a) op pic_float(b))); \