diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-22 01:08:49 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-22 01:08:49 +0000 |
commit | 2c1936cf87184470308b6bf3f0fe70f1a99936af (patch) | |
tree | 5106a7c0d110bdeb516cec6a948803901cb737a5 /numeric.c | |
parent | 12d17449532803979139cce212124f0e17a4728d (diff) | |
download | ruby-2c1936cf87184470308b6bf3f0fe70f1a99936af.tar.gz |
* 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
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 7 |
1 files changed, 2 insertions, 5 deletions
@@ -1479,17 +1479,14 @@ flo_round(int argc, VALUE *argv, VALUE num) { VALUE nd; double number, f; - int ndigits = 0, i; + int ndigits = 0; long val; if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) { ndigits = NUM2INT(nd); } number = RFLOAT_VALUE(num); - f = 1.0; - i = abs(ndigits); - while (--i >= 0) - f = f*10.0; + f = pow(10, abs(ndigits)); if (isinf(f)) { if (ndigits < 0) number = 0; |