From: Konrad Meyer Date: 2007-10-14T17:02:12+09:00 Subject: Re: Bug: Numeric#divmod calculates wrongly --nextPart2732551.RkItB5kZgM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Dirk Traulsen: > Am 8 Oct 2007 um 19:49 hat Dirk Traulsen geschrieben: >=20 > > Output: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > > ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]=20 > ..=20 > > x.divmod(y) > > ----------- > > [6, 0.08] > > [6, 0.00666666666666667] > > [6, 0.0466666666666667] > > [6, 0.0766666666666667] > > [8, 0.00333333333333341] > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D > >=20 > > As you can see the divisor 7 is wrongly displayed as 6, while the=20 > > modulos are correct. > >=20 >=20 > I tested Numeric#divmod on two more systems: SUSE 10.1 and Kubuntu=20 > 6.10. > They both run Ruby 1.8.4 and under both systems Numeric#divmod works=20 > correctly! > So this bug was either introduced between Ruby 1.8.4 and 1.8.6 or it is=20 > a problem depending on the OS. >=20 > Could somebody please confirm these findings? Especially with other=20 > System and Ruby version combinations this would be really helpful to=20 > nail down this massive bug. A computer should really calculate=20 > correctly... >=20 > Dirk Traulsen >=20 >=20 > The testcode: >=20 > x=3D[0.58, 0.59, 0.63, 0.66, 0.67] > y=3D1/12.0 >=20 > z1=3Dx.map {|a| a/y} > z2=3Dx.map {|a| a.divmod(y).inspect} >=20 > a=3D[RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM] > puts "ruby #{a[0]} (#{a[1]}) [#{a[2]}]" > puts > print 'x=3D' > p x > puts 'y=3D1/12.0' > puts > puts "x/y\n---" > puts z1 > puts > puts "x.divmod(y)\n-----------" > puts z2 >=20 >=20 > gives under > SUSE 10.1: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > ruby 1.8.4 (2005-12-24) [i586-linux] >=20 > x=3D[0.58, 0.59, 0.63, 0.66, 0.67] > y=3D1/12.0 >=20 > x/y > --- > 6.96 > 7.08 > 7.56 > 7.92 > 8.04 >=20 > x.divmod(y) > ----------- > [6.0, 0.08] > [7.0, 0.00666666666666667] > [7.0, 0.0466666666666667] > [7.0, 0.0766666666666667] > [8.0, 0.00333333333333341] > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D >=20 >=20 > and Kubuntu 6.10: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D > ruby 1.8.4 (2005-12-24) [i586-linux] >=20 > x=3D[0.58, 0.59, 0.63, 0.66, 0.67] > y=3D1/12.0 >=20 > x/y > --- > 6.96 > 7.08 > 7.56 > 7.92 > 8.04 >=20 > x.divmod(y) > ----------- > [6.0, 0.08] > [7.0, 0.00666666666666667] > [7.0, 0.0466666666666667] > [7.0, 0.0766666666666667] > [8.0, 0.00333333333333341] > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D I can't confirm this (incorrect) behaviour. 0.58.divmod(1/12.0) # =3D> [6.0, 0.08] 0.59.divmod(1/12.0) # =3D> [7.0, 0.00666666666666667] Ruby 1.8.6, Fedora 7. Regards, =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart2732551.RkItB5kZgM Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHEc0ACHB0oCiR2cwRAmU5AJ9/8CvLhvxWhLnqDFNMRGFZTJoZ9wCfatIW jwQn2X8iNAzIp3QfsdVPOns= =fzTC -----END PGP SIGNATURE----- --nextPart2732551.RkItB5kZgM--