From bdebc184fa006a6a12a8e935eac20800c48b394a Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 17 Feb 2010 22:08:37 -0800 Subject: [PATCH] Fix problem converting negative bignums to flonums. --- src/microcode/intprm.c | 18 ++++-------------- src/microcode/object.h | 4 ++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/microcode/intprm.c b/src/microcode/intprm.c index 28a9e96c2..26e5c0aef 100644 --- a/src/microcode/intprm.c +++ b/src/microcode/intprm.c @@ -142,20 +142,10 @@ 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)) - { - long X = (FIXNUM_TO_LONG (integer)); - double Y = ((double) X); - - if (((long) Y) == X) - PRIMITIVE_RETURN (FIXNUM_TO_FLONUM (integer)); - if ((control & 2) != 0) - error_bad_range_arg (1); - PRIMITIVE_RETURN (SHARP_F); - } - if (bignum_fits_in_word_p - (integer, - (((control & 1) != 0) ? DBL_MANT_DIG : DBL_MAX_EXP), - 0)) + PRIMITIVE_RETURN (FIXNUM_TO_FLONUM (integer)); + if (((control & 1) != 0) + ? (LOSSLESS_BIGNUM_TO_DOUBLE_P (integer)) + : (BIGNUM_TO_DOUBLE_P (integer))) PRIMITIVE_RETURN (BIGNUM_TO_FLONUM (integer)); if ((control & 2) != 0) error_bad_range_arg (1); diff --git a/src/microcode/object.h b/src/microcode/object.h index 69582e57b..916843e7e 100644 --- a/src/microcode/object.h +++ b/src/microcode/object.h @@ -387,10 +387,10 @@ extern SCHEME_OBJECT * memory_base; (bignum_fits_in_word_p ((bignum), ((sizeof (unsigned long)) * CHAR_BIT), 0)) #define BIGNUM_TO_DOUBLE_P(bignum) \ - (bignum_fits_in_word_p ((bignum), DBL_MAX_EXP, 0)) + (bignum_fits_in_word_p ((bignum), (DBL_MAX_EXP + 1), 1)) #define LOSSLESS_BIGNUM_TO_DOUBLE_P(bignum) \ - (bignum_fits_in_word_p ((bignum), DBL_MANT_DIG, 0)) + (bignum_fits_in_word_p ((bignum), (DBL_MANT_DIG + 1), 1)) /* Flonum Operations */ -- 2.25.1