[#85940] [Ruby trunk Bug#14578] Forking a child process inside of a mutex crashes the ruby interpreter — ben.govero@...
Issue #14578 has been reported by bengovero (Ben Govero).
3 messages
2018/03/05
[#86205] [Ruby trunk Feature#14618] Add display width method to String for CLI — aycabta@...
SXNzdWUgIzE0NjE4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGF5Y2FidGEgKGF5Y2FidGEgLikuCgot
3 messages
2018/03/19
[#86366] Re: [ruby-cvs:70102] usa:r63008 (trunk): get rid of test error/failure on Windows introduced at r62955 — Eric Wong <normalperson@...>
usa@ruby-lang.org wrote:
3 messages
2018/03/28
[ruby-core:86330] [Ruby trunk Bug#14637] Rational#to_f returns a wrong result when denominator is big
From:
mame@...
Date:
2018-03-27 13:49:15 UTC
List:
ruby-core #86330
Issue #14637 has been reported by mame (Yusuke Endoh).
----------------------------------------
Bug #14637: Rational#to_f returns a wrong result when denominator is big
https://bugs.ruby-lang.org/issues/14637
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
For example, `Rational(1, 10**23).to_f` returns a wrong result:
```
$ ruby -e 'p Rational(1, 10**23).to_f'
1.0000000000000001e-23
```
It should be `1.0e-23`. A Float value `1.0000000000000001e-23` ranges from `0.1000000000000000033903094915171e-22` to `0.1000000000000000180839888707781e-22`. This range does not include `1 / 10**23`.
This is because Rational#to_f does: (1) translate numerator and denominator to double values, and (2) divide them. When denominator is big, it cannot translate denominator to double accurately, which causes the above bug.
We can avoid this inaccurance by translating numerator and denominator to small bignums, instead of double values.
```diff
diff --git a/bignum.c b/bignum.c
index b4c7560034..fd5f385cac 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6178,9 +6178,7 @@ rb_big_fdiv_double(VALUE x, VALUE y)
return big_fdiv_int(x, rb_int2big(FIX2LONG(y)));
}
else if (RB_BIGNUM_TYPE_P(y)) {
- dy = rb_big2dbl(y);
- if (isinf(dx) || isinf(dy))
- return big_fdiv_int(x, y);
+ return big_fdiv_int(x, y);
}
else if (RB_FLOAT_TYPE_P(y)) {
dy = RFLOAT_VALUE(y);
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>