From: Francis Cianfrocca Date: 2006-05-18T06:40:50+09:00 Subject: Re: greatest float smaller than 1.0? ------=_Part_125202_13390928.1147902045024 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Floating point libraries are really weird and platform-dependent, especiall= y in regard to subtraction, which doesn't behave very well between numbers that are many orders of magnitude apart. What happens on your hardware if you do 1.0 + Float::EPSILON? Again, it seems to me that the OP might want to look for a more portable wa= y to solve his problem. On 5/17/06, Joel VanderWerf wrote: > > polypus wrote: > > how do i get the greatest float smaller than 1.0? > > > > thanks > > > > Something like this maybe? > > irb(main):006:0> [0.9999999999999999].pack "G" > =3D> "?\357\377\377\377\377\377\377" > > (that was just to find out what floats look like in memory, big-endian). > > irb(main):012:0> x =3D ("?\357" + "\377"*100).unpack "G" > =3D> [1.0] > irb(main):013:0> "%30f" % x > =3D> "0.999999999999999888977697537484" > > Dunno if that's safe on all platforms... > > Incidentally, something is wrong with Float::EPSILON, which Mauricio > suggested and should (AFAIK) work: > > irb(main):016:0* f =3D (1.0 - Float::EPSILON) > =3D> 1.0 > irb(main):017:0> "%.20f" % f > =3D> "0.99999999999999977796" > irb(main):019:0> x[0]-f > =3D> 1.11022302462516e-16 > > Whaa??? > > -- > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > > ------=_Part_125202_13390928.1147902045024--