Skip to content

Commit afea338

Browse files
committed
2 parents 1f30693 + e0a394d commit afea338

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/snippets/floats.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
b = 1.3
55
c = 1.2
66
assert a < b
7+
assert not b < a
78
assert a <= b
89
assert a <= c
10+
11+
assert b > a
12+
assert not a > b
13+
assert not a > c

vm/src/obj/objfloat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ fn float_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
9191
Ok(vm.ctx.new_bool(result))
9292
}
9393

94+
fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
95+
arg_check!(
96+
vm,
97+
args,
98+
required = [
99+
(zelf, Some(vm.ctx.float_type())),
100+
(other, Some(vm.ctx.float_type()))
101+
]
102+
);
103+
let zelf = get_value(zelf);
104+
let other = get_value(other);
105+
let result = zelf > other;
106+
Ok(vm.ctx.new_bool(result))
107+
}
108+
94109
fn float_abs(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
95110
arg_check!(vm, args, required = [(i, Some(vm.ctx.float_type()))]);
96111
Ok(vm.ctx.new_float(get_value(i).abs()))
@@ -204,6 +219,7 @@ pub fn init(context: &PyContext) {
204219
float_type.set_attr("__eq__", context.new_rustfunc(float_eq));
205220
float_type.set_attr("__lt__", context.new_rustfunc(float_lt));
206221
float_type.set_attr("__le__", context.new_rustfunc(float_le));
222+
float_type.set_attr("__gt__", context.new_rustfunc(float_gt));
207223
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
208224
float_type.set_attr("__add__", context.new_rustfunc(float_add));
209225
float_type.set_attr("__divmod__", context.new_rustfunc(float_divmod));

0 commit comments

Comments
 (0)