| 127 | } |
| 128 | |
| 129 | pub 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 | |
| 149 | fn 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")) |