From 4c0bf87f8bed19fb69a4ca40b308712d624fb98f Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 12 Feb 2020 17:18:35 -0500 Subject: [PATCH] Issue #357 - Do not truncate results of integer division --- CHANGELOG.md | 4 ++++ runtime.c | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be8eed0..5e1ef65b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.15 - TBD +Bug Fixes + +- Prevent truncation when dividing two fixnums. + ## 0.14 - February 11, 2020 Cyclone now automatically relocates any stack objects when performing a mutation. This prevents a whole range of race conditions that had previously been possible in multithreaded application code. And since this work is done by the Cyclone runtime no special code needs to be added to your applications. diff --git a/runtime.c b/runtime.c index 95dfa0ad..e2457b65 100644 --- a/runtime.c +++ b/runtime.c @@ -3969,7 +3969,6 @@ object Cyc_fast_mul(void *data, object ptr, object x, object y) { } object Cyc_fast_div(void *data, object ptr, object x, object y) { - int z; // x is int (assume value types for integers) if (obj_is_int(x)){ if (obj_is_int(y)){ @@ -3977,8 +3976,8 @@ object Cyc_fast_div(void *data, object ptr, object x, object y) { // Overflow can occur if y = 0 || (x = 0x80000000 && y = -1) // We already check for 0 above and the value of x above is a // bignum, so no futher checks are required. - z = obj_obj2int(x) / obj_obj2int(y); - return obj_int2obj(z); + assign_double(ptr, (double)(obj_obj2int(x)) / obj_obj2int(y)); + return ptr; } else if (is_object_type(y) && type_of(y) == double_tag) { assign_double(ptr, (double)(obj_obj2int(x)) / double_value(y)); return ptr;