From 4a598d03e28536fb40c6dbd87be03c9b85bdf8ff Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 1 May 2019 03:37:01 +0900 Subject: [PATCH] Add float.imag, float.conjugate --- tests/snippets/floats.py | 2 ++ vm/src/obj/objfloat.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/tests/snippets/floats.py b/tests/snippets/floats.py index d409463ee..0ba3460a9 100644 --- a/tests/snippets/floats.py +++ b/tests/snippets/floats.py @@ -140,6 +140,8 @@ assert_raises(OverflowError, lambda: 1.2 ** (10 ** 1000)) assert 3 ** 2.0 == 9.0 assert (1.7).real == 1.7 +assert (1.7).imag == 0.0 +assert (1.7).conjugate() == 1.7 assert (1.3).is_integer() == False assert (1.0).is_integer() == True diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index fabe99246..ea58fed58 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -364,6 +364,16 @@ impl PyFloat { zelf } + #[pyproperty(name = "imag")] + fn imag(&self, _vm: &VirtualMachine) -> f64 { + 0.0f64 + } + + #[pymethod(name = "conjugate")] + fn conjugate(zelf: PyRef, _vm: &VirtualMachine) -> PyFloatRef { + zelf + } + #[pymethod(name = "is_integer")] fn is_integer(&self, _vm: &VirtualMachine) -> bool { let v = self.value;