D
Dirk Traulsen
Hi all!
I submitted the following bug report to
http://rubyforge.org/tracker/index.php?func=detail&aid=14540&
group_id=426&atid=1698
===================================================
There is a calculating bug in Numeric#divmod.
The divisor is reproducibly calculated wrongly for certain numbers.
See the following example to illustrate the problem:
x=[0.58, 0.59, 0.63, 0.66, 0.67]
y=1/12.0
z1=x.map {|a| a/y}
z2=x.map {|a| a.divmod(y).inspect}
a=[RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PATCHLEVEL, RUBY_PLATFORM]
puts "ruby #{a[0]} (#{a[1]} patchlevel #{a[2].to_s}) [#{a[3]}]"
puts
print 'x='
p x
puts 'y=1/12.0'
puts
puts "x/y\n---"
puts z1
puts
puts "x.divmod(y)\n-----------"
puts z2
Output:
=================================================
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
x=[0.58, 0.59, 0.63, 0.66, 0.67]
y=1/12.0
x/y
---
6.96
7.08
7.56
7.92
8.04
x.divmod(y)
-----------
[6, 0.08]
[6, 0.00666666666666667]
[6, 0.0466666666666667]
[6, 0.0766666666666667]
[8, 0.00333333333333341]
=================================================
As you can see the divisor 7 is wrongly displayed as 6, while the
modulos are correct.
Dirk Traulsen
I submitted the following bug report to
http://rubyforge.org/tracker/index.php?func=detail&aid=14540&
group_id=426&atid=1698
===================================================
There is a calculating bug in Numeric#divmod.
The divisor is reproducibly calculated wrongly for certain numbers.
See the following example to illustrate the problem:
x=[0.58, 0.59, 0.63, 0.66, 0.67]
y=1/12.0
z1=x.map {|a| a/y}
z2=x.map {|a| a.divmod(y).inspect}
a=[RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PATCHLEVEL, RUBY_PLATFORM]
puts "ruby #{a[0]} (#{a[1]} patchlevel #{a[2].to_s}) [#{a[3]}]"
puts
print 'x='
p x
puts 'y=1/12.0'
puts
puts "x/y\n---"
puts z1
puts
puts "x.divmod(y)\n-----------"
puts z2
Output:
=================================================
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
x=[0.58, 0.59, 0.63, 0.66, 0.67]
y=1/12.0
x/y
---
6.96
7.08
7.56
7.92
8.04
x.divmod(y)
-----------
[6, 0.08]
[6, 0.00666666666666667]
[6, 0.0466666666666667]
[6, 0.0766666666666667]
[8, 0.00333333333333341]
=================================================
As you can see the divisor 7 is wrongly displayed as 6, while the
modulos are correct.
Dirk Traulsen