From 59417ea451768f38c6da874004fe3fd01c80488a Mon Sep 17 00:00:00 2001 From: Bojan Date: Sun, 28 Oct 2018 00:36:51 +0200 Subject: [PATCH] Added __ge__ to float --- tests/snippets/floats.py | 4 ++++ vm/src/obj/objfloat.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/snippets/floats.py b/tests/snippets/floats.py index a4382b9f1..cf6a9a0c0 100644 --- a/tests/snippets/floats.py +++ b/tests/snippets/floats.py @@ -11,3 +11,7 @@ assert a <= c assert b > a assert not a > b assert not a > c +assert b >= a +assert c >= a +assert not a >= b + diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index acabdbbef..9ca0258c9 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -106,6 +106,21 @@ fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { Ok(vm.ctx.new_bool(result)) } +fn float_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + arg_check!( + vm, + args, + required = [ + (zelf, Some(vm.ctx.float_type())), + (other, Some(vm.ctx.float_type())) + ] + ); + let zelf = get_value(zelf); + let other = get_value(other); + let result = zelf >= other; + Ok(vm.ctx.new_bool(result)) +} + fn float_abs(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { arg_check!(vm, args, required = [(i, Some(vm.ctx.float_type()))]); Ok(vm.ctx.new_float(get_value(i).abs())) @@ -220,6 +235,7 @@ pub fn init(context: &PyContext) { float_type.set_attr("__lt__", context.new_rustfunc(float_lt)); float_type.set_attr("__le__", context.new_rustfunc(float_le)); float_type.set_attr("__gt__", context.new_rustfunc(float_gt)); + float_type.set_attr("__ge__", context.new_rustfunc(float_ge)); float_type.set_attr("__abs__", context.new_rustfunc(float_abs)); float_type.set_attr("__add__", context.new_rustfunc(float_add)); float_type.set_attr("__divmod__", context.new_rustfunc(float_divmod));