mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Added __ge__ to float
This commit is contained in:
1 parent
afea338c08
commit
59417ea451
2 files changed
+20
No files matched your search
@@ -11,3 +11,7 @@ assert a <= c
|
||||
assert b > a
|
||||
assert not a > b
|
||||
assert not a > c
|
||||
assert b >= a
|
||||
assert c >= a
|
||||
assert not a >= b
|
||||
|
||||
@@ -106,6 +106,21 @@ fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
Ok(vm.ctx.new_bool(result))
|
||||
}
|
||||
|
||||
fn float_ge(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_abs(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(i, Some(vm.ctx.float_type()))]);
|
||||
Ok(vm.ctx.new_float(get_value(i).abs()))
|
||||
@@ -220,6 +235,7 @@ pub fn init(context: &PyContext) {
|
||||
float_type.set_attr("__lt__", context.new_rustfunc(float_lt));
|
||||
float_type.set_attr("__le__", context.new_rustfunc(float_le));
|
||||
float_type.set_attr("__gt__", context.new_rustfunc(float_gt));
|
||||
float_type.set_attr("__ge__", context.new_rustfunc(float_ge));
|
||||
float_type.set_attr("__abs__", context.new_rustfunc(float_abs));
|
||||
float_type.set_attr("__add__", context.new_rustfunc(float_add));
|
||||
float_type.set_attr("__divmod__", context.new_rustfunc(float_divmod));
|
||||
|
||||
Reference in new issue
Block a user