Issue #357 - Do not truncate results of integer division

This commit is contained in:
Justin Ethier 2020-02-12 17:18:35 -05:00
parent ec4a0cd02a
commit 4c0bf87f8b
2 changed files with 6 additions and 3 deletions

View file

@ -2,6 +2,10 @@
## 0.15 - TBD ## 0.15 - TBD
Bug Fixes
- Prevent truncation when dividing two fixnums.
## 0.14 - February 11, 2020 ## 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. 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.

View file

@ -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) { object Cyc_fast_div(void *data, object ptr, object x, object y) {
int z;
// x is int (assume value types for integers) // x is int (assume value types for integers)
if (obj_is_int(x)){ if (obj_is_int(x)){
if (obj_is_int(y)){ 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) // Overflow can occur if y = 0 || (x = 0x80000000 && y = -1)
// We already check for 0 above and the value of x above is a // We already check for 0 above and the value of x above is a
// bignum, so no futher checks are required. // bignum, so no futher checks are required.
z = obj_obj2int(x) / obj_obj2int(y); assign_double(ptr, (double)(obj_obj2int(x)) / obj_obj2int(y));
return obj_int2obj(z); return ptr;
} else if (is_object_type(y) && type_of(y) == double_tag) { } else if (is_object_type(y) && type_of(y) == double_tag) {
assign_double(ptr, (double)(obj_obj2int(x)) / double_value(y)); assign_double(ptr, (double)(obj_obj2int(x)) / double_value(y));
return ptr; return ptr;