diff --git a/Cargo.lock b/Cargo.lock index c113248b6..9ca4e6a0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1259,17 +1259,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-rational" version = "0.4.0" @@ -2048,7 +2037,6 @@ dependencies = [ "num-bigint", "num-complex", "num-integer", - "num-iter", "num-rational", "num-traits", "num_cpus", diff --git a/vm/Cargo.toml b/vm/Cargo.toml index e1ff9a6a4..d983ba6c3 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -38,7 +38,6 @@ num-bigint = { version = "0.4.0", features = ["serde"] } num-traits = "0.2.8" num-integer = "0.1.41" num-rational = "0.4.0" -num-iter = "0.1.39" rand = "0.8" rand_core = "0.6" getrandom = { version = "0.2", features = ["js"] } diff --git a/vm/src/stdlib/math.rs b/vm/src/stdlib/math.rs index fcd100e87..a2cd36cf8 100644 --- a/vm/src/stdlib/math.rs +++ b/vm/src/stdlib/math.rs @@ -473,13 +473,20 @@ fn math_fsum(iter: PyIterable, vm: &VirtualMachine) -> PyResult PyResult { let value = value.borrow_value(); + let one = BigInt::one(); if value.is_negative() { return Err(vm.new_value_error("factorial() not defined for negative values".to_owned())); - } else if *value <= BigInt::one() { - return Ok(BigInt::from(1u64)); + } else if *value <= one { + return Ok(one); } - let ret: BigInt = num_iter::range_inclusive(BigInt::from(1u64), value.clone()).product(); - Ok(ret) + // start from 2, since we know that value > 1 and 1*2=2 + let mut current = one + 1; + let mut product = BigInt::from(2u8); + while current < *value { + current += 1; + product *= ¤t; + } + Ok(product) } fn math_modf(x: IntoPyFloat) -> (f64, f64) {