From 2bf083856b52e93eb3348771f92e14bce83c4444 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sun, 10 Jun 2012 00:46:18 +0200 Subject: [PATCH] simplify ecl_to_float() and use it everywhere instead of number_to_float() --- src/c/cmpaux.d | 24 ------------------------ src/c/number.d | 25 +++++++++++++++++++++++++ src/c/numbers/cos.d | 2 +- src/c/numbers/cosh.d | 2 +- src/c/numbers/exp.d | 2 +- src/c/numbers/log.d | 10 +++++----- src/c/numbers/sin.d | 2 +- src/c/numbers/sinh.d | 2 +- src/c/numbers/sqrt.d | 2 +- src/c/numbers/tan.d | 2 +- src/c/numbers/tanh.d | 2 +- src/h/external.h | 4 +--- src/h/legacy.h | 5 +++++ 13 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/c/cmpaux.d b/src/c/cmpaux.d index 8e790c1a9..597d8af93 100644 --- a/src/c/cmpaux.d +++ b/src/c/cmpaux.d @@ -112,30 +112,6 @@ ecl_to_unsigned_integer(cl_object x) } } -float -ecl_to_float(cl_object x) -{ - if (ECL_FIXNUMP(x)) return(ecl_fixnum(x)); /* Immediate fixnum */ - - switch (type_of(x)) { -/* case t_fixnum: return ecl_fixnum(x); */ -/* case t_character: return ECL_CHAR_CODE(x); */ - case t_bignum: - case t_ratio: - return ecl_to_double(x); - case t_singlefloat: - return ecl_single_float(x); - case t_doublefloat: - return ecl_double_float(x); -#ifdef ECL_LONG_FLOAT - case t_longfloat: - return ecl_long_float(x); -#endif - default: - FEwrong_type_nth_arg(@[coerce], 1, x, @[real]); - } -} - int ecl_aref_bv(cl_object x, cl_index index) { diff --git a/src/c/number.d b/src/c/number.d index 9127e5da8..bf9d07843 100644 --- a/src/c/number.d +++ b/src/c/number.d @@ -743,6 +743,31 @@ ratio_to_long_double(cl_object num, cl_object den) } #endif /* ECL_LONG_FLOAT */ +float +ecl_to_float(cl_object x) +{ + if (ECL_FIXNUMP(x)) return(ecl_fixnum(x)); /* Immediate fixnum */ + + switch (type_of(x)) { + case t_fixnum: + return (float)ecl_fixnum(x); + case t_bignum: + return (float)ratio_to_double(x, ecl_make_fixnum(1)); + case t_ratio: + return (float)ratio_to_double(x->ratio.num, x->ratio.den); + case t_singlefloat: + return ecl_single_float(x); + case t_doublefloat: + return (float)ecl_double_float(x); +#ifdef ECL_LONG_FLOAT + case t_longfloat: + return (float)ecl_long_float(x); +#endif + default: + FEwrong_type_nth_arg(@[coerce], 1, x, @[real]); + } +} + double ecl_to_double(cl_object x) { diff --git a/src/c/numbers/cos.d b/src/c/numbers/cos.d index 986bc3042..0c2988e2c 100644 --- a/src/c/numbers/cos.d +++ b/src/c/numbers/cos.d @@ -31,7 +31,7 @@ cl_cos(cl_object x) static cl_object ecl_cos_rational(cl_object x) { - return ecl_make_single_float(cosf(number_to_float(x))); + return ecl_make_single_float(cosf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/cosh.d b/src/c/numbers/cosh.d index 1580ad578..dc65d9121 100644 --- a/src/c/numbers/cosh.d +++ b/src/c/numbers/cosh.d @@ -31,7 +31,7 @@ cl_cosh(cl_object x) static cl_object ecl_cosh_rational(cl_object x) { - return ecl_make_single_float(coshf(number_to_float(x))); + return ecl_make_single_float(coshf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/exp.d b/src/c/numbers/exp.d index d5b33c44d..e39d6ec04 100644 --- a/src/c/numbers/exp.d +++ b/src/c/numbers/exp.d @@ -31,7 +31,7 @@ cl_exp(cl_object x) static cl_object ecl_exp_rational(cl_object x) { - return ecl_make_single_float(expf(number_to_float(x))); + return ecl_make_single_float(expf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/log.d b/src/c/numbers/log.d index 0c9df41b1..a46c302f7 100644 --- a/src/c/numbers/log.d +++ b/src/c/numbers/log.d @@ -58,7 +58,7 @@ ecl_log1_bignum(cl_object x) } else { cl_fixnum l = ecl_integer_length(x) - 1; cl_object r = ecl_make_ratio(x, ecl_ash(ecl_make_fixnum(1), l)); - float d = logf(number_to_float(r)) + l * logf(2.0); + float d = logf(ecl_to_float(r)) + l * logf(2.0); return ecl_make_single_float(d); } } @@ -66,9 +66,9 @@ ecl_log1_bignum(cl_object x) static cl_object ecl_log1_rational(cl_object x) { - float f = number_to_float(x); + float f = ecl_to_float(x); if (f < 0) return ecl_log1_complex_inner(x, ecl_make_fixnum(0)); - return ecl_make_single_float(logf(number_to_float(x))); + return ecl_make_single_float(logf(ecl_to_float(x))); } static cl_object @@ -179,9 +179,9 @@ ecl_log1p_simple(cl_object x) static cl_object ecl_log1p_rational(cl_object x) { - float f = number_to_float(x); + float f = ecl_to_float(x); if (f < -1) return ecl_log1p_simple(x); - return ecl_make_single_float(log1pf(number_to_float(x))); + return ecl_make_single_float(log1pf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/sin.d b/src/c/numbers/sin.d index 834ef8fea..09102c342 100644 --- a/src/c/numbers/sin.d +++ b/src/c/numbers/sin.d @@ -31,7 +31,7 @@ cl_sin(cl_object x) static cl_object ecl_sin_rational(cl_object x) { - return ecl_make_single_float(sinf(number_to_float(x))); + return ecl_make_single_float(sinf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/sinh.d b/src/c/numbers/sinh.d index 41fba3dca..3fa6dd81a 100644 --- a/src/c/numbers/sinh.d +++ b/src/c/numbers/sinh.d @@ -31,7 +31,7 @@ cl_sinh(cl_object x) static cl_object ecl_sinh_rational(cl_object x) { - return ecl_make_single_float(sinhf(number_to_float(x))); + return ecl_make_single_float(sinhf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/sqrt.d b/src/c/numbers/sqrt.d index 79279ad4a..e0964d7e3 100644 --- a/src/c/numbers/sqrt.d +++ b/src/c/numbers/sqrt.d @@ -35,7 +35,7 @@ ecl_sqrt_rational(cl_object x) x = ecl_sqrt_rational(ecl_negate(x)); return ecl_make_complex(ecl_make_fixnum(0), x); } else { - return ecl_make_single_float(sqrtf(number_to_float(x))); + return ecl_make_single_float(sqrtf(ecl_to_float(x))); } } diff --git a/src/c/numbers/tan.d b/src/c/numbers/tan.d index 24d974490..511e1e3a8 100644 --- a/src/c/numbers/tan.d +++ b/src/c/numbers/tan.d @@ -43,7 +43,7 @@ cl_tan(cl_object x) static cl_object ecl_tan_rational(cl_object x) { - return ecl_make_single_float(safe_tanf(number_to_float(x))); + return ecl_make_single_float(safe_tanf(ecl_to_float(x))); } static cl_object diff --git a/src/c/numbers/tanh.d b/src/c/numbers/tanh.d index 7f3c6d0c6..cb952311a 100644 --- a/src/c/numbers/tanh.d +++ b/src/c/numbers/tanh.d @@ -31,7 +31,7 @@ cl_tanh(cl_object x) static cl_object ecl_tanh_rational(cl_object x) { - return ecl_make_single_float(tanhf(number_to_float(x))); + return ecl_make_single_float(tanhf(ecl_to_float(x))); } static cl_object diff --git a/src/h/external.h b/src/h/external.h index fd529fc2b..03893e681 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -500,8 +500,6 @@ extern ECL_API cl_fixnum ecl_imod(cl_fixnum x, cl_fixnum y); extern ECL_API char ecl_to_char(cl_object x); extern ECL_API cl_fixnum ecl_to_fixnum(cl_object x); extern ECL_API cl_index ecl_to_unsigned_integer(cl_object x); -extern ECL_API float ecl_to_float(cl_object x); -extern ECL_API double ecl_to_double(cl_object x); extern ECL_API int ecl_aref_bv(cl_object x, cl_index index); extern ECL_API int ecl_aset_bv(cl_object x, cl_index index, int value); extern ECL_API void cl_throw(cl_object tag) /*ecl_attr_noreturn*/; @@ -1110,8 +1108,8 @@ extern ECL_API cl_object ecl_make_double_float(double f); extern ECL_API cl_object ecl_make_complex(cl_object r, cl_object i); extern ECL_API cl_object cl_rational(cl_object x); #define cl_rationalize cl_rational +extern ECL_API float ecl_to_float(cl_object x); extern ECL_API double ecl_to_double(cl_object x); -#define number_to_float(x) ((float)ecl_to_double(x)) #ifdef ECL_LONG_FLOAT extern ECL_API long double ecl_to_long_double(cl_object x); extern ECL_API cl_object ecl_make_long_float(long double f); diff --git a/src/h/legacy.h b/src/h/legacy.h index 6cbb22a73..df02a776b 100644 --- a/src/h/legacy.h +++ b/src/h/legacy.h @@ -117,3 +117,8 @@ #define ecl_make_singlefloat ecl_make_single_float #define ecl_make_doublefloat ecl_make_double_float #define ecl_make_longfloat ecl_make_long_float + +#define number_to_float(x) ((float)ecl_to_double(x)) + +#define ecl_make_unsigned_long_Long(o) ecl_make_ulong_long(o) +#define ecl_to_unsigned_long_long(o) ecl_to_ulong_long(o)