From: Juergen Strobel Date: 2006-07-08T15:26:38+09:00 Subject: Re: Float#==. Legacy? --ZRyEpB+iJ+qUx0kp Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 08, 2006 at 11:22:37AM +0900, Guillaume Marcais wrote: > Le 7 juil. 06, =E0 15:30, Joel VanderWerf a =E9crit : >=20 > > > >The Float#=3D~ that Martin suggested is nice, but it still doesn't help= =20 > >with one of the problems which (I think) the OP wanted: > > > >x =3D 1.2 > >y =3D 1.2000000000000001 > >p(x =3D~ y) # =3D> true > >p([x] =3D~ [y]) # =3D> false > > >=20 > Yes, this is what I was referring to. >=20 > I came about a little differently. Mainly that calling=20 > Float#within_delta or equivalent is easy when I have the float itself,=20 > but if is embedded in an Array or Hash, it renders #=3D=3D useless on the= =20 > structure: >=20 > [1+1, 3] =3D=3D [2, 3] # =3D> true > [0.1+0.2, 3] =3D=3D [0.3, 3] # =3D> false >=20 > For the second case, one would needs to loop on the elements of the=20 > array. >=20 > And my second realization is if Float#=3D=3D is (almost) always a mistake= ,=20 > why not change it to something useful most of the time. Changing=20 > Float#=3D=3D in my code the way I did make me a little nervous as it is= =20 > changing a pretty fundamental behavior, but on the other hand it is=20 > hardly ever used and it made sense in my case. >=20 > Guillaume. But the current #=3D=3D is the best you can come up with in general. There is no universally correct epsilon, it depends on the operations and actual numbers used so far, and small errors in successive floating point operations do accumulate, sometimes drastically. A whole subfield of mathematics is concerned with this. Depending on your code, you might have to apply different epsilons even to floats in the same array. If it makes sense in your code go for it, but this depends on your code and would do more harm than good in general. -J=FCrgen --=20 The box said it requires Windows 95 or better so I installed Linux --ZRyEpB+iJ+qUx0kp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iQEVAwUBRK9K4/y64gyiEfXtAQKlDAf/aY7EIXFJa1mhRYuPxfeAckz6uavzWqIV TB4eOB8QoVvRvINmlne7HbRec7X78v0CW3Nd0nIKAnlRDbnUpXIJB0oHy9jOEUgc 3kfji0+D8DVtDXp4sQI2OIdCiMEkrcpY9gI5l5Y00j9GRPR3mV8nqZ8towbzFtwS 1qfdiRyKdCzbbc/qyrnPw/Cvxs10Ss/cHH/l8Vj/Q4+wivVwbGh9ItDXnQ0s/Afz sASU39nlE4wibIcEUXmX/aElNw9Thzv0Gwf2CTYy3G3K6t26SqKTXDxMshgO9s2n odCAd0akirE9hsgyffnZ3n94KdzUbtQtUiAVIF/KmdyOyRDxhrSacw== =fJRz -----END PGP SIGNATURE----- --ZRyEpB+iJ+qUx0kp--