From 438a33cafb164dacdee9d074373847f5bd34fb19 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sun, 16 Dec 2012 00:47:15 +0100 Subject: [PATCH] Simplify ecl_truncate1() on rationals --- src/c/numbers/floor.d | 1 + src/c/numbers/truncate.d | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/c/numbers/floor.d b/src/c/numbers/floor.d index 552981f0a..31729f6bf 100644 --- a/src/c/numbers/floor.d +++ b/src/c/numbers/floor.d @@ -19,6 +19,7 @@ #ifndef HAVE_ISOC99 # define floorf floor #endif +#include #include @(defun floor (x &optional (y OBJNULL)) diff --git a/src/c/numbers/truncate.d b/src/c/numbers/truncate.d index 6b13c7240..9f93d8047 100644 --- a/src/c/numbers/truncate.d +++ b/src/c/numbers/truncate.d @@ -25,7 +25,6 @@ cl_object ecl_truncate1(cl_object x) { - const cl_env_ptr the_env = ecl_process_env(); cl_object v0, v1; switch (ecl_t_of(x)) { case t_fixnum: @@ -34,9 +33,10 @@ ecl_truncate1(cl_object x) v1 = ecl_make_fixnum(0); break; case t_ratio: - v0 = ecl_truncate2(x->ratio.num, x->ratio.den); - v1 = ecl_make_ratio(ecl_nth_value(the_env, 1), x->ratio.den); - break; + if (ecl_plusp(x->ratio.num)) + return ecl_floor1(x); + else + return ecl_ceiling1(x); case t_singlefloat: { float d = ecl_single_float(x); float y = d > 0? floorf(d) : ceilf(d); @@ -63,7 +63,10 @@ ecl_truncate1(cl_object x) default: FEwrong_type_nth_arg(@[truncate],1,x,@[real]); } - ecl_return2(the_env, v0, v1); + { + const cl_env_ptr the_env = ecl_process_env(); + ecl_return2(the_env, v0, v1); + } } cl_object