From: Joel VanderWerf Date: 2006-05-18T06:26:56+09:00 Subject: Re: greatest float smaller than 1.0? 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" => "?\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 = ("?\357" + "\377"*100).unpack "G" => [1.0] irb(main):013:0> "%30f" % x => "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 = (1.0 - Float::EPSILON) => 1.0 irb(main):017:0> "%.20f" % f => "0.99999999999999977796" irb(main):019:0> x[0]-f => 1.11022302462516e-16 Whaa??? -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407