Skip to content

Commit 1c814ff

Browse files
committed
Add float.__rpow__
1 parent 09710b5 commit 1c814ff

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tests/snippets/floats.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137

138138
assert 1.2 ** 2 == 1.44
139139
assert_raises(OverflowError, lambda: 1.2 ** (10 ** 1000))
140+
assert 3 ** 2.0 == 9.0
140141

141142
assert (1.7).real == 1.7
142143
assert (1.3).is_integer() == False

vm/src/obj/objfloat.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ impl PyFloat {
284284
)
285285
}
286286

287+
#[pymethod(name = "__rpow__")]
288+
fn rpow(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
289+
try_float(&other, vm)?.map_or_else(
290+
|| Ok(vm.ctx.not_implemented()),
291+
|other| other.powf(self.value).into_pyobject(vm),
292+
)
293+
}
294+
287295
#[pymethod(name = "__sub__")]
288296
fn sub(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
289297
try_float(&other, vm)?.map_or_else(

0 commit comments

Comments
 (0)