* numeric.c (flo_round): use pow instead of while-loop. fixes #4510
patched by Alex Young [ruby-core:35526] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
12d1744953
commit
2c1936cf87
@ -1,3 +1,8 @@
|
|||||||
|
Tue Mar 22 09:38:19 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (flo_round): use pow instead of while-loop. fixes #4510
|
||||||
|
patched by Alex Young [ruby-core:35526]
|
||||||
|
|
||||||
Tue Mar 22 06:47:46 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
Tue Mar 22 06:47:46 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/date/date_strftime.c (date_strftime_wo_timespec):
|
* ext/date/date_strftime.c (date_strftime_wo_timespec):
|
||||||
|
@ -1479,17 +1479,14 @@ flo_round(int argc, VALUE *argv, VALUE num)
|
|||||||
{
|
{
|
||||||
VALUE nd;
|
VALUE nd;
|
||||||
double number, f;
|
double number, f;
|
||||||
int ndigits = 0, i;
|
int ndigits = 0;
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) {
|
if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) {
|
||||||
ndigits = NUM2INT(nd);
|
ndigits = NUM2INT(nd);
|
||||||
}
|
}
|
||||||
number = RFLOAT_VALUE(num);
|
number = RFLOAT_VALUE(num);
|
||||||
f = 1.0;
|
f = pow(10, abs(ndigits));
|
||||||
i = abs(ndigits);
|
|
||||||
while (--i >= 0)
|
|
||||||
f = f*10.0;
|
|
||||||
|
|
||||||
if (isinf(f)) {
|
if (isinf(f)) {
|
||||||
if (ndigits < 0) number = 0;
|
if (ndigits < 0) number = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user