From ca66eb1c9a64bb54fb6685aed7dacc892f919e5c Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 13 Nov 2007 16:34:45 +0000 Subject: * numeric.c (round): fallback definition. * numeric.c (flo_divmod, flo_round): use round() always. [ruby-dev:32269] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index ef199fe66..9c3ab2a86 100644 --- a/numeric.c +++ b/numeric.c @@ -63,6 +63,24 @@ #define DBL_EPSILON 2.2204460492503131e-16 #endif +#ifndef HAVE_ROUND +double +round(double x) +{ + double f; + + if (x > 0.0) { + f = floor(x); + x = f + (x - f >= 0.5); + } + else if (x < 0.0) { + f = ceil(x); + x = f - (f - x >= 0.5); + } + return x; +} +#endif + static ID id_coerce, id_to_i, id_eq; VALUE rb_cNumeric; @@ -718,11 +736,7 @@ flo_divmod(VALUE x, VALUE y) } flodivmod(RFLOAT_VALUE(x), fy, &div, &mod); if (FIXABLE(div)) { -#ifdef HVAE_ROUND val = round(div); -#else - val = (div < 0) ? ceil(x - 0.5) : floor(x + 0.5); -#endif a = LONG2FIX(val); } else if (isnan(div) || isinf(div)) { @@ -1261,8 +1275,7 @@ flo_round(int argc, VALUE *argv, VALUE num) if (ndigits < 0) number /= f; else number *= f; - if (number > 0.0) number = floor(number+0.5); - if (number < 0.0) number = ceil(number-0.5); + number = round(number); if (ndigits < 0) number *= f; else number /= f; -- cgit