From: Matthias Reitinger Date: 2009-04-29T05:17:27+09:00 Subject: Re: Detecting -0.0 Joel VanderWerf wrote: > Thomas B. wrote: >> Hello. >> >> I have a simple question - how to detect if a variable contains a Float >> of value -0.0? Is there any special method for this, or any comparison >> that distinguishes negative zero from a the regular zero? >> >> Thanks in advance. >> TPR. > > irb(main):001:0> x = -0.0 > => -0.0 > irb(main):002:0> x == 0.0 > => true > irb(main):003:0> x.eql?(0.0) > => true > irb(main):004:0> x.equal?(0.0) > => false irb(main):001:0> x = 0.0 => 0.0 irb(main):002:0> x == 0.0 => true irb(main):003:0> x.eql?(0.0) => true irb(main):004:0> x.equal?(0.0) => false In short: you cannot distinguish between 0.0 and -0.0 this way. -Matthias -- Posted via http://www.ruby-forum.com/.