mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (flo_round): Fix criteria for 32 bits platform
part 2 of [bug #5276] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
73bb2a29f9
commit
3dc28710c9
2 changed files with 10 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Sep 6 06:44:25 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* numeric.c (flo_round): Fix criteria for 32 bits platform
|
||||||
|
part 2 of [bug #5276]
|
||||||
|
|
||||||
Tue Sep 6 05:37:11 2011 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
Tue Sep 6 05:37:11 2011 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||||
|
|
||||||
* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures
|
* test/rinda/test_rinda.rb (test_core_03_notify): Fixed test failures
|
||||||
|
|
10
numeric.c
10
numeric.c
|
@ -1560,16 +1560,16 @@ flo_round(int argc, VALUE *argv, VALUE num)
|
||||||
10 ** ((binexp-1)/log_2(10)) <= |number| < 10 ** (binexp/log_2(10))
|
10 ** ((binexp-1)/log_2(10)) <= |number| < 10 ** (binexp/log_2(10))
|
||||||
If binexp >= 0, and since log_2(10) = 3.322259:
|
If binexp >= 0, and since log_2(10) = 3.322259:
|
||||||
10 ** (binexp/4 - 1) < |number| < 10 ** (binexp/3)
|
10 ** (binexp/4 - 1) < |number| < 10 ** (binexp/3)
|
||||||
binexp/4 <= exp <= binexp/3
|
floor(binexp/4) <= exp <= ceil(binexp/3)
|
||||||
If binexp <= 0, swap the /4 and the /3
|
If binexp <= 0, swap the /4 and the /3
|
||||||
So if ndigits + binexp/(4 or 3) >= float_dig, the result is number
|
So if ndigits + floor(binexp/(4 or 3)) >= float_dig, the result is number
|
||||||
If ndigits + binexp/(3 or 4) < 0 the result is 0
|
If ndigits + ceil(binexp/(3 or 4)) < 0 the result is 0
|
||||||
*/
|
*/
|
||||||
if (isinf(number) || isnan(number) ||
|
if (isinf(number) || isnan(number) ||
|
||||||
(((long)ndigits - float_dig) * (3 + (binexp > 0)) + binexp >= 0)) {
|
(ndigits >= float_dig - (binexp > 0 ? binexp / 4 : binexp / 3 - 1))) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
if ((long)ndigits * (4 - (binexp > 0)) + binexp < 0) {
|
if (ndigits < - (binexp > 0 ? binexp / 3 + 1 : binexp / 4)) {
|
||||||
return DBL2NUM(0);
|
return DBL2NUM(0);
|
||||||
}
|
}
|
||||||
f = pow(10, ndigits);
|
f = pow(10, ndigits);
|
||||||
|
|
Loading…
Add table
Reference in a new issue