[Numpy-discussion] Equvalent function for Ceil() and Floor()

Chris Barker - NOAA Federal chris.barker at noaa.gov
Mon May 20 12:03:53 EDT 2013


On Mon, May 20, 2013 at 8:54 AM, Bakhtiyor Zokhidov
<bakhtiyor_zokhidov at mail.ru> wrote:

> what about the following example:
>>>>new_ceil(-0.24, 0.25)
> -0.0

ceil rounds toward +inf (and floor towards -inf) -- this is exactly
what you want if you're doing what I think you are...(note that
round() rounds towards and away from zero -- so different for negative
numbers...)

the minus sign means "minus 0.0", which is a seemingly odd floating
point thing -- but FP numbers have a sign bit, which, in this case, is
set to negative, even though, mathematically speaking, 0.0 doesn't
have a sign. But it will compare to 0.0 as you'd expect:

In [8]: -0.0 == 0.0
Out[8]: True

In [9]: -0.0 <  0.0
Out[9]: False

-Chris

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list