MCPcopy Index your code
hub / github.com/RustPython/RustPython / floor

Function floor

crates/stdlib/src/math.rs:385–400  ·  view source on GitHub ↗
(x: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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) {

Callers 1

choicesMethod · 0.85

Calls 7

try_magic_methodFunction · 0.85
try_float_optMethod · 0.80
to_f64Method · 0.80
ErrClass · 0.50
has_attrMethod · 0.45
classMethod · 0.45
new_intMethod · 0.45

Tested by

no test coverage detected