M. Edward (Ed) Borasky
10/14/2007 10:45:00 AM
Dirk Traulsen wrote:
> Am 8 Oct 2007 um 19:49 hat Dirk Traulsen geschrieben:
>
>> Output:
>> =================================================
>> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
> ..
>> 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.
>>
>
> I tested Numeric#divmod on two more systems: SUSE 10.1 and Kubuntu
> 6.10.
> They both run Ruby 1.8.4 and under both systems Numeric#divmod works
> correctly!
> So this bug was either introduced between Ruby 1.8.4 and 1.8.6 or it is
> a problem depending on the OS.
>
> Could somebody please confirm these findings? Especially with other
> System and Ruby version combinations this would be really helpful to
> nail down this massive bug. A computer should really calculate
> correctly...
>
> Dirk Traulsen
>
>
> The testcode:
>
> 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_PLATFORM]
> puts "ruby #{a[0]} (#{a[1]}) [#{a[2]}]"
> 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
>
>
> gives under
> SUSE 10.1:
> ===================================================
> ruby 1.8.4 (2005-12-24) [i586-linux]
>
> 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, 0.08]
> [7.0, 0.00666666666666667]
> [7.0, 0.0466666666666667]
> [7.0, 0.0766666666666667]
> [8.0, 0.00333333333333341]
> ===================================================
>
>
> and Kubuntu 6.10:
> ===================================================
> ruby 1.8.4 (2005-12-24) [i586-linux]
>
> 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, 0.08]
> [7.0, 0.00666666666666667]
> [7.0, 0.0466666666666667]
> [7.0, 0.0766666666666667]
> [8.0, 0.00333333333333341]
> ===================================================
>
>
>
And on Gentoo Linux with ruby-1.8.6-p110-r1
$ ruby divmod-test.rb
ruby 1.8.6 (2007-09-24) [i686-linux]
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]
[7, 0.00666666666666667]
[7, 0.0466666666666667]
[7, 0.0766666666666667]
[8, 0.00333333333333341]
If it matters, the hardware is an Athlon Thunderbird and Ruby was
compiled from source, as most of Gentoo is, using gcc 4.2.1 and CFLAGS
"-march athlon-tbird -O2". So ... where is it broken again?
Dirk says "ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] is broken"
Dirk says "Kubuntu 6.10 and SuSE 10.1 using Ruby 1.8.4 works."
Konrad says "two test cases worked on Fedora 7 with 1.8.6"
And I have it working on Ruby 1.8.6-p110 on Gentoo, compiled from source
with GCC 4.2.1
And Eric has it broken on PowerPC Macs for both Ruby 1.8.6 and Ruby 1.9.0
Eric, what compiler made the Ruby interpreters on your PowerPC?
And everybody -- recompile ruby-1.8.6-p111 and see whether it works or
not. I say it's a compiler problem at this point -- maybe
over-aggressive floating-point optimization?? I doubt if the Ruby source
is broken.