(x: PyObjectRef, vm: &VirtualMachine)
| 383 | |
| 384 | #[pyfunction] |
| 385 | fn floor(x: PyObjectRef, vm: &VirtualMachine) -> PyResult { |
| 386 | // Only call __floor__ if the class defines it - if it exists but is not callable, |
| 387 | // the error should be propagated (not fall back to float conversion) |
| 388 | if x.class().has_attr(identifier!(vm, __floor__)) { |
| 389 | return try_magic_method(identifier!(vm, __floor__), vm, &x); |
| 390 | } |
| 391 | // __floor__ not defined - fall back to float conversion |
| 392 | if let Some(v) = x.try_float_opt(vm) { |
| 393 | let v = try_f64_to_bigint(v?.to_f64().floor(), vm)?; |
| 394 | return Ok(vm.ctx.new_int(v).into()); |
| 395 | } |
| 396 | Err(vm.new_type_error(format!( |
| 397 | "type '{}' doesn't define '__floor__' method", |
| 398 | x.class().name(), |
| 399 | ))) |
| 400 | } |
| 401 | |
| 402 | #[pyfunction] |
| 403 | fn frexp(x: ArgIntoFloat) -> (f64, i32) { |
no test coverage detected