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

Function try_to_bigint

crates/vm/src/builtins/float.rs:129–147  ·  view source on GitHub ↗
(value: f64, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

127}
128
129pub fn try_to_bigint(value: f64, vm: &VirtualMachine) -> PyResult<BigInt> {
130 match value.to_bigint() {
131 Some(int) => Ok(int),
132 None => {
133 if value.is_infinite() {
134 Err(vm
135 .new_overflow_error("OverflowError: cannot convert float infinity to integer"))
136 } else if value.is_nan() {
137 Err(vm.new_value_error("ValueError: cannot convert float NaN to integer"))
138 } else {
139 // unreachable unless BigInt has a bug
140 unreachable!(
141 "A finite float value failed to be converted to bigint: {}",
142 value
143 )
144 }
145 }
146 }
147}
148
149fn inner_floordiv(v1: f64, v2: f64, vm: &VirtualMachine) -> PyResult<f64> {
150 float_ops::floordiv(v1, v2).ok_or_else(|| vm.new_zero_division_error("division by zero"))

Callers 5

__trunc__Method · 0.85
__floor__Method · 0.85
__ceil__Method · 0.85
__round__Method · 0.85
as_numberMethod · 0.85

Calls 3

ErrClass · 0.50
is_infiniteMethod · 0.45
is_nanMethod · 0.45

Tested by

no test coverage detected