diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-13 16:34:45 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-13 16:34:45 +0000 |
| commit | ca66eb1c9a64bb54fb6685aed7dacc892f919e5c (patch) | |
| tree | ca3beaa3907e686eb815f70f06c35bfedf843bd2 /numeric.c | |
| parent | 5cfe7b5250f3e762be7f36106b1b13e48f7bda1a (diff) | |
| download | ruby-ca66eb1c9a64bb54fb6685aed7dacc892f919e5c.tar.gz ruby-ca66eb1c9a64bb54fb6685aed7dacc892f919e5c.tar.xz ruby-ca66eb1c9a64bb54fb6685aed7dacc892f919e5c.zip | |
* 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
Diffstat (limited to 'numeric.c')
| -rw-r--r-- | numeric.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -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; |
