From 99e034859f66b6e8ccb8ba230a6bf0c9dd7f3bbd Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 7 Jul 2010 18:50:37 +0000 Subject: [PATCH] Fix bug in INTEGER->FLONUM primitive on 64-bit systems. Not all fixnums can be converted losslessly into flonums. --- src/microcode/intprm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/microcode/intprm.c b/src/microcode/intprm.c index 26e5c0aef..22d40bfca 100644 --- a/src/microcode/intprm.c +++ b/src/microcode/intprm.c @@ -142,7 +142,16 @@ DEFINE_PRIMITIVE ("INTEGER->FLONUM", Prim_integer_to_flonum, 2, 2, 0) SCHEME_OBJECT integer = (ARG_REF (1)); long control = (arg_index_integer (2, 4)); if (FIXNUM_P (integer)) - PRIMITIVE_RETURN (FIXNUM_TO_FLONUM (integer)); + { + double d = (FIXNUM_TO_DOUBLE (integer)); + if ((0 == (control & 1)) + || ((DOUBLE_TO_FIXNUM_P (d)) + && (integer == (DOUBLE_TO_FIXNUM (d))))) + PRIMITIVE_RETURN (double_to_flonum (d)); + if ((control & 2) != 0) + error_bad_range_arg (1); + PRIMITIVE_RETURN (SHARP_F); + } if (((control & 1) != 0) ? (LOSSLESS_BIGNUM_TO_DOUBLE_P (integer)) : (BIGNUM_TO_DOUBLE_P (integer))) -- 2.25.1