From: Jeff Schwab Date: 2009-04-29T05:30:02+09:00 Subject: Re: Detecting -0.0 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? NB: I'm not sure how portable this is. def negative_zero?(number) inverse = 1 / number.to_f inverse < 0 && inverse.infinite? ? true : false end [ 0.0, # false -0.0, # true -1.0, # false 1.0 # false ].each do |f| puts negative_zero?(f) end