From: nobu@...
Date: 2016-12-28T03:11:25+00:00
Subject: [ruby-core:78886] [Ruby trunk Bug#13078] with Integer a and b, a.fdiv(b) sometimes inaccurate than Rational(a, b).to_f

Issue #13078 has been updated by Nobuyoshi Nakada.


I thought the reduction would be slower, but actually not significant.

```
$ ruby -rbenchmark -e 'a = 3; b = -0x20_0000_0000_0001; n=10_000_000; Benchmark.bm(13) {|x|x.report("Integer#fdiv"){n.times{a.fdiv(b)}}; x.report("Rational#to_f"){n.times{Rational(a, b).to_f}}}'
                    user     system      total        real
Integer#fdiv    3.420000   0.000000   3.420000 (  3.446264)
Rational#to_f   3.450000   0.010000   3.460000 (  3.465592)
```

----------------------------------------
Bug #13078: with Integer a and b, a.fdiv(b) sometimes inaccurate than Rational(a, b).to_f
https://bugs.ruby-lang.org/issues/13078#change-62298

* Author: Makoto Kishimoto
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
For example,

~~~
a = 3
b = 0x20_0000_0000_0001
p a.fdiv(b)
p Rational(a, b).to_f

#=>
3.3306690738754696e-16
3.330669073875469e-16
~~~
I'm hacking to solve this problem, see diff view.
https://github.com/ruby/ruby/compare/trunk...metanest:fdiv_spike



-- 
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>