mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Don't depend on num-iter
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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 *= ¤t;
|
||||
}
|
||||
Ok(product)
|
||||
}
|
||||
|
||||
fn math_modf(x: IntoPyFloat) -> (f64, f64) {
|
||||
|
||||
Reference in New Issue
Block a user