From: "M. Edward (Ed) Borasky" Date: 2007-10-15T05:56:04+09:00 Subject: Re: Bug: Numeric#divmod calculates wrongly Eric Hodel wrote: > 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. > > $ gcc -v > [...] > gcc version 4.0.1 (Apple Computer, Inc. build 5367) > $ ruby19 -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]' > ruby 1.9.0 (2007-10-13 patchlevel 0) [powerpc-darwin8.10.0] > "-g -O2 -pipe -fno-common" > $ ruby18 -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]' > ruby 1.8.6 (2007-09-23 patchlevel 5000) [powerpc-darwin8.10.0] > "-g -O2 -fno-schedule-insns2 -pipe -fno-common" > > -fno-schedule-insns2 is to work around a GCC bug. > > -- > Poor workers blame their tools. Good workers build better tools. The > best workers get their tools to do the work for them. -- Syndicate Wars > > > > As an aside, I downloaded "paranoia" (http://netlib2.cs.utk.edu/paranoia/paranoia.c) and ELEFUNT (http://www.math.utah.edu/pub/elefunt/elefunt.tar.gz) and ran them with gcc 4.2.2 on my Athlon64. "paranoia" tests the basic floating point hardware, and ELEFUNT tests the math libraries. I'm satisfied from those tests that gcc is "doing the right thing". 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.