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

Function ceil

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

Source from the content-addressed store, hash-verified

365
366 #[pyfunction]
367 fn ceil(x: PyObjectRef, vm: &VirtualMachine) -> PyResult {
368 // Only call __ceil__ if the class defines it - if it exists but is not callable,
369 // the error should be propagated (not fall back to float conversion)
370 if x.class().has_attr(identifier!(vm, __ceil__)) {
371 return try_magic_method(identifier!(vm, __ceil__), vm, &x);
372 }
373 // __ceil__ not defined - fall back to float conversion
374 if let Some(v) = x.try_float_opt(vm) {
375 let v = try_f64_to_bigint(v?.to_f64().ceil(), vm)?;
376 return Ok(vm.ctx.new_int(v).into());
377 }
378 Err(vm.new_type_error(format!(
379 "type '{}' doesn't define '__ceil__' method",
380 x.class().name(),
381 )))
382 }
383
384 #[pyfunction]
385 fn floor(x: PyObjectRef, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

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