numeric.c: dbl2ival no longer rounds
* numeric.c (flodivmod): round division if it is a finite number and module is required. * numeric.c (dbl2ival): do not round here. * numeric.c (flo_ceil): use dbl2ival. * numeric.c (flo_round): round explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2b82986034
commit
b4c0aac4c8
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Sun Apr 3 09:34:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (flodivmod): round division if it is a finite number
|
||||||
|
and module is required.
|
||||||
|
|
||||||
|
* numeric.c (dbl2ival): do not round here.
|
||||||
|
|
||||||
|
* numeric.c (flo_ceil): use dbl2ival.
|
||||||
|
|
||||||
|
* numeric.c (flo_round): round explicitly.
|
||||||
|
|
||||||
Sat Apr 2 15:24:18 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Apr 2 15:24:18 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* include/ruby/intern.h (rb_check_arity): returns argc.
|
* include/ruby/intern.h (rb_check_arity): returns argc.
|
||||||
|
15
numeric.c
15
numeric.c
@ -1008,8 +1008,10 @@ flodivmod(double x, double y, double *divp, double *modp)
|
|||||||
}
|
}
|
||||||
if (isinf(x) && !isinf(y))
|
if (isinf(x) && !isinf(y))
|
||||||
div = x;
|
div = x;
|
||||||
else
|
else {
|
||||||
div = (x - mod) / y;
|
div = (x - mod) / y;
|
||||||
|
if (modp && divp) div = round(div);
|
||||||
|
}
|
||||||
if (y*mod < 0) {
|
if (y*mod < 0) {
|
||||||
mod += y;
|
mod += y;
|
||||||
div -= 1.0;
|
div -= 1.0;
|
||||||
@ -1066,7 +1068,6 @@ flo_mod(VALUE x, VALUE y)
|
|||||||
static VALUE
|
static VALUE
|
||||||
dbl2ival(double d)
|
dbl2ival(double d)
|
||||||
{
|
{
|
||||||
d = round(d);
|
|
||||||
if (FIXABLE(d)) {
|
if (FIXABLE(d)) {
|
||||||
return LONG2FIX((long)d);
|
return LONG2FIX((long)d);
|
||||||
}
|
}
|
||||||
@ -1761,13 +1762,7 @@ static VALUE
|
|||||||
flo_ceil(VALUE num)
|
flo_ceil(VALUE num)
|
||||||
{
|
{
|
||||||
double f = ceil(RFLOAT_VALUE(num));
|
double f = ceil(RFLOAT_VALUE(num));
|
||||||
long val;
|
return dbl2ival(f);
|
||||||
|
|
||||||
if (!FIXABLE(f)) {
|
|
||||||
return rb_dbl2big(f);
|
|
||||||
}
|
|
||||||
val = (long)f;
|
|
||||||
return LONG2FIX(val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1856,7 +1851,7 @@ flo_round(int argc, VALUE *argv, VALUE num)
|
|||||||
}
|
}
|
||||||
number = RFLOAT_VALUE(num);
|
number = RFLOAT_VALUE(num);
|
||||||
if (ndigits == 0) {
|
if (ndigits == 0) {
|
||||||
return dbl2ival(number);
|
return dbl2ival(round(number));
|
||||||
}
|
}
|
||||||
frexp(number, &binexp);
|
frexp(number, &binexp);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user