Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/snippets/floats.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
1 + 1.1

a = 1.2
b = 1.3
c = 1.2
assert a < b
assert a <= b
assert a <= c
16 changes: 16 additions & 0 deletions vm/src/obj/objfloat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ fn float_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
Ok(vm.ctx.new_bool(result))
}

fn float_lt(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_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(
vm,
Expand Down Expand Up @@ -186,6 +201,7 @@ fn float_pow(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
pub fn init(context: &PyContext) {
let ref float_type = context.float_type;
float_type.set_attr("__eq__", context.new_rustfunc(float_eq));
float_type.set_attr("__lt__", context.new_rustfunc(float_lt));
float_type.set_attr("__le__", context.new_rustfunc(float_le));
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
float_type.set_attr("__add__", context.new_rustfunc(float_add));
Expand Down