===================================================
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:
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
…
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…
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…
It’s correct on my system:
Debian lenny (testing)
Linux 2.6.21-2-686 #1 SMP Wed Jul 11 03:53:02 UTC 2007 i686 GNU/Linux
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.
On Oct 14, 2007, at 03:44 , M. Edward (Ed) Borasky wrote:
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.
An exercise to the student would be to port these two test suites to
Ruby and see how well they do. But relative to the bug in question, I
ran the divmod.rb with all optimization turned off on the Athlon64 using
gcc 4.2.2 and it’s broken.
I took a look at “numeric.c” in Ruby 1.8.6-p111 to see what “divmod” is
actually doing. I was somewhat disturbed by the complicated path that it
takes to get its answer, and in thinking about the function itself, I
wonder what its usefulness is, given the willy-nilly way it flits
between integer and floating point arithmetic. And it’s essentially
doing “divmod” by doing a “div” and a “mod”, so there’s no efficiency
gain, unlike what you’d have in the integer case where you do a divide
and get the remainder for free, at least at the hardware level.
Does the original poster have an actual use case for “divmod” in its
present definition? I couldn’t think of any use for it in its present
definition. What I would find useful would be something that took a
Bignum dividend and divisor and returned the Bignum quotient and
remainder.
On Oct 14, 2007, at 03:44 , M. Edward (Ed) Borasky wrote:
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?
I don’t believe that anyone has brought up the intel Macs as yet, but
I get the same results as the OP on my MacBook:
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.2]