Implement __ceil__ for float type

Co-authored-by: Tetramad <cbwjd777@gmail.com>
This commit is contained in:
Padraic FanningandTetramad authored and Tetramad committed 2021-08-11 14:30:10 +09:00
1 parent 9f497fb65a
commit fae7b0e8ed
2 files changed
+5 -2

No files matched your search

-2
View File
@@ -340,8 +340,6 @@ class GeneralFloatCases(unittest.TestCase):
self.assertRaises(OverflowError, float("inf").__floor__)
self.assertRaises(OverflowError, float("-inf").__floor__)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_float_ceil(self):
self.assertIsInstance(float(0.5).__ceil__(), int)
self.assertEqual(float(0.5).__ceil__(), 1)
+5
View File
@@ -389,6 +389,11 @@ impl PyFloat {
try_bigint(self.value, vm)
}
#[pymethod(magic)]
fn ceil(&self, vm: &VirtualMachine) -> PyResult<BigInt> {
try_bigint(self.value.ceil(), vm)
}
#[pymethod(name = "__round__")]
fn round(&self, ndigits: OptionalOption<PyIntRef>, vm: &VirtualMachine) -> PyResult {
let ndigits = ndigits.flatten();