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

Method as_integer_ratio

crates/vm/src/builtins/float.rs:359–373  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

357
358 #[pymethod]
359 fn as_integer_ratio(&self, vm: &VirtualMachine) -> PyResult<(PyIntRef, PyIntRef)> {
360 let value = self.value;
361
362 float_to_ratio(value)
363 .map(|(numer, denom)| (vm.ctx.new_bigint(&numer), vm.ctx.new_bigint(&denom)))
364 .ok_or_else(|| {
365 if value.is_infinite() {
366 vm.new_overflow_error("cannot convert Infinity to integer ratio")
367 } else if value.is_nan() {
368 vm.new_value_error("cannot convert NaN to integer ratio")
369 } else {
370 unreachable!("finite float must able to convert to integer ratio")
371 }
372 })
373 }
374
375 #[pyclassmethod]
376 fn from_number(cls: PyTypeRef, number: PyObjectRef, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 6

float_to_ratioFunction · 0.85
ok_or_elseMethod · 0.80
new_bigintMethod · 0.80
mapMethod · 0.45
is_infiniteMethod · 0.45
is_nanMethod · 0.45

Tested by

no test coverage detected