Don't depend on num-iter

This commit is contained in:
Noah
2020-12-21 14:49:44 -06:00
parent 2e33b227b3
commit 8ae26e545f
3 changed files with 11 additions and 17 deletions

12
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"] }

View File

@@ -473,13 +473,20 @@ fn math_fsum(iter: PyIterable<IntoPyFloat>, vm: &VirtualMachine) -> PyResult<f64
fn math_factorial(value: PyIntRef, vm: &VirtualMachine) -> PyResult<BigInt> {
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 *= &current;
}
Ok(product)
}
fn math_modf(x: IntoPyFloat) -> (f64, f64) {