Skip to content

Commit 57dbfd1

Browse files
Merge pull request RustPython#177 from BojanKogoj/bojan/objfloat-__lt__
Added __lt__ for float
2 parents 1d854a8 + a2889f1 commit 57dbfd1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/snippets/floats.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
1 + 1.1
2+
3+
a = 1.2
4+
b = 1.3
5+
c = 1.2
6+
assert a < b
7+
assert a <= b
8+
assert a <= c

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_lt(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_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
6580
arg_check!(
6681
vm,
@@ -187,6 +202,7 @@ fn float_pow(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
187202
pub fn init(context: &PyContext) {
188203
let ref float_type = context.float_type;
189204
float_type.set_attr("__eq__", context.new_rustfunc(float_eq));
205+
float_type.set_attr("__lt__", context.new_rustfunc(float_lt));
190206
float_type.set_attr("__le__", context.new_rustfunc(float_le));
191207
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
192208
float_type.set_attr("__add__", context.new_rustfunc(float_add));

0 commit comments

Comments
 (0)