Skip to content

Commit 068489b

Browse files
Merge pull request RustPython#178 from BojanKogoj/bojan/objfloat-__le__
Added __le__ for float
2 parents 29ce0cf + 89e03d0 commit 068489b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

vm/src/obj/objfloat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ fn float_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6161
Ok(vm.ctx.new_bool(result))
6262
}
6363

64+
fn float_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
65+
arg_check!(
66+
vm,
67+
args,
68+
required = [
69+
(zelf, Some(vm.ctx.float_type())),
70+
(other, Some(vm.ctx.float_type()))
71+
]
72+
);
73+
let zelf = get_value(zelf);
74+
let other = get_value(other);
75+
let result = zelf <= other;
76+
Ok(vm.ctx.new_bool(result))
77+
}
78+
6479
fn float_abs(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6580
arg_check!(vm, args, required = [(i, Some(vm.ctx.float_type()))]);
6681
Ok(vm.ctx.new_float(get_value(i).abs()))
@@ -171,6 +186,7 @@ fn float_pow(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
171186
pub fn init(context: &PyContext) {
172187
let ref float_type = context.float_type;
173188
float_type.set_attr("__eq__", context.new_rustfunc(float_eq));
189+
float_type.set_attr("__le__", context.new_rustfunc(float_le));
174190
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
175191
float_type.set_attr("__add__", context.new_rustfunc(float_add));
176192
float_type.set_attr("__divmod__", context.new_rustfunc(float_divmod));

0 commit comments

Comments
 (0)