Skip to content

Commit a318e4e

Browse files
committed
objfloat.rs try_float for common operand handling
1 parent 177704f commit a318e4e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

vm/src/obj/objfloat.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ impl From<f64> for PyFloat {
4141
}
4242
}
4343

44+
fn try_float(value: &PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<f64>> {
45+
Ok(if objtype::isinstance(&value, &vm.ctx.float_type()) {
46+
Some(get_value(&value))
47+
} else if objtype::isinstance(&value, &vm.ctx.int_type()) {
48+
Some(objint::get_float_value(&value, vm)?)
49+
} else {
50+
None
51+
})
52+
}
53+
4454
fn mod_(v1: f64, v2: f64, vm: &VirtualMachine) -> PyResult {
4555
if v2 != 0.0 {
4656
Ok(vm.ctx.new_float(v1 % v2))

0 commit comments

Comments
 (0)