Skip to content

Commit abe6aba

Browse files
Merge pull request RustPython#181 from BojanKogoj/bojan/objfloat-__ge__
Added __ge__ to float
2 parents 6190914 + 59417ea commit abe6aba

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/snippets/floats.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
assert b > a
1212
assert not a > b
1313
assert not a > c
14+
assert b >= a
15+
assert c >= a
16+
assert not a >= b
17+

vm/src/obj/objfloat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
106106
Ok(vm.ctx.new_bool(result))
107107
}
108108

109+
fn float_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
110+
arg_check!(
111+
vm,
112+
args,
113+
required = [
114+
(zelf, Some(vm.ctx.float_type())),
115+
(other, Some(vm.ctx.float_type()))
116+
]
117+
);
118+
let zelf = get_value(zelf);
119+
let other = get_value(other);
120+
let result = zelf >= other;
121+
Ok(vm.ctx.new_bool(result))
122+
}
123+
109124
fn float_abs(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
110125
arg_check!(vm, args, required = [(i, Some(vm.ctx.float_type()))]);
111126
Ok(vm.ctx.new_float(get_value(i).abs()))
@@ -220,6 +235,7 @@ pub fn init(context: &PyContext) {
220235
float_type.set_attr("__lt__", context.new_rustfunc(float_lt));
221236
float_type.set_attr("__le__", context.new_rustfunc(float_le));
222237
float_type.set_attr("__gt__", context.new_rustfunc(float_gt));
238+
float_type.set_attr("__ge__", context.new_rustfunc(float_ge));
223239
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
224240
float_type.set_attr("__add__", context.new_rustfunc(float_add));
225241
float_type.set_attr("__divmod__", context.new_rustfunc(float_divmod));

0 commit comments

Comments
 (0)