def test_floorceiltrunc(self): from _numpypy import array, floor, ceil, trunc import math ninf, inf = float("-inf"), float("inf") a = array([ninf, -1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5, inf]) assert ([ninf, -2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] == floor(a)).all() assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0, inf] == ceil(a)).all() assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] == trunc(a)).all() assert all([math.isnan(f(float("nan"))) for f in floor, ceil, trunc])
def test_floorceil(self): from _numpypy import array, floor, ceil import math reference = [-2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0] a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5]) b = floor(a) for i in range(5): assert b[i] == reference[i] reference = [-1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0] a = array([-1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5]) b = ceil(a) assert (reference == b).all() inf = float("inf") data = [1.5, 2.9999, -1.999, inf] results = [math.floor(x) for x in data] assert (floor(data) == results).all() results = [math.ceil(x) for x in data] assert (ceil(data) == results).all()
def test_floorceiltrunc(self): from _numpypy import array, floor, ceil, trunc import math ninf, inf = float("-inf"), float("inf") a = array([ninf, -1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5, inf]) assert ([ninf, -2.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] == floor(a)).all() assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 2.0, 1.0, inf] == ceil(a)).all() assert ([ninf, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 0.0, inf] == trunc(a)).all() assert all([math.isnan(f(float("nan"))) for f in floor, ceil, trunc]) assert all([ math.copysign(1, f(abs(float("nan")))) == 1 for f in floor, ceil, trunc ]) assert all([ math.copysign(1, f(-abs(float("nan")))) == -1 for f in floor, ceil, trunc ])