[pypy-commit] pypy default: add float.is_integer()

gutworth noreply at buildbot.pypy.org
Sat Oct 29 01:30:51 CEST 2011


Author: Benjamin Peterson <benjamin at python.org>
Branch: 
Changeset: r48593:b9587add901b
Date: 2011-10-28 19:30 -0400
http://bitbucket.org/pypy/pypy/changeset/b9587add901b/

Log:	add float.is_integer()

diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -546,6 +546,9 @@
     # Try to return int.
     return space.newtuple([space.int(w_num), space.int(w_den)])
 
+def float_is_integer__Float(space, w_float):
+    return space.wrap(math.floor(w_float.floatval) == w_float.floatval)
+
 from pypy.objspace.std import floattype
 register_all(vars(), floattype)
 
diff --git a/pypy/objspace/std/floattype.py b/pypy/objspace/std/floattype.py
--- a/pypy/objspace/std/floattype.py
+++ b/pypy/objspace/std/floattype.py
@@ -12,6 +12,7 @@
 
 
 float_as_integer_ratio = SMM("as_integer_ratio", 1)
+float_is_integer = SMM("is_integer", 1)
 float_hex = SMM("hex", 1)
 
 def descr_conjugate(space, w_float):
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -63,6 +63,10 @@
     def setup_class(cls):
         cls.w_py26 = cls.space.wrap(sys.version_info >= (2, 6))
 
+    def test_isinteger(self):
+        assert (1.).is_integer()
+        assert not (1.1).is_integer()
+
     def test_conjugate(self):
         assert (1.).conjugate() == 1.
         assert (-1.).conjugate() == -1.
@@ -782,4 +786,4 @@
         # divide by 0
         raises(ZeroDivisionError, lambda: inf % 0)
         raises(ZeroDivisionError, lambda: inf // 0)
-        raises(ZeroDivisionError, divmod, inf, 0)
\ No newline at end of file
+        raises(ZeroDivisionError, divmod, inf, 0)


More information about the pypy-commit mailing list