Skip to content

Commit de0d323

Browse files
authored
change dependency from num-bigint to malachite-bigint (RustPython#4952)
1 parent 7a3f965 commit de0d323

35 files changed

+365
-155
lines changed

Cargo.lock

Lines changed: 253 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ rustpython-pylib = { path = "pylib" }
2929
rustpython-stdlib = { path = "stdlib" }
3030
rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" }
3131

32-
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" }
33-
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" }
34-
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" }
35-
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" }
36-
rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "fdec727f8068c882f99a47f0439572a71fd98b28" }
32+
rustpython-literal = { git = "https://github.com/RustPython/Parser.git", rev = "b2f95e284852cb25d6e510c127260d03573d9f0c" }
33+
rustpython-parser-core = { git = "https://github.com/RustPython/Parser.git", rev = "b2f95e284852cb25d6e510c127260d03573d9f0c" }
34+
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "b2f95e284852cb25d6e510c127260d03573d9f0c" }
35+
rustpython-ast = { git = "https://github.com/RustPython/Parser.git", rev = "b2f95e284852cb25d6e510c127260d03573d9f0c" }
36+
rustpython-format = { git = "https://github.com/RustPython/Parser.git", rev = "b2f95e284852cb25d6e510c127260d03573d9f0c" }
3737
# rustpython-literal = { path = "../RustPython-parser/literal" }
3838
# rustpython-parser-core = { path = "../RustPython-parser/core" }
3939
# rustpython-parser = { path = "../RustPython-parser/parser" }
@@ -58,10 +58,11 @@ itertools = "0.10.3"
5858
libc = "0.2.133"
5959
log = "0.4.16"
6060
nix = "0.26"
61+
malachite-bigint = { version = "0.1.0" }
62+
malachite-q = "0.3.2"
63+
malachite-base = "0.3.2"
6164
num-complex = "0.4.0"
62-
num-bigint = "0.4.3"
6365
num-integer = "0.1.44"
64-
num-rational = "0.4.0"
6566
num-traits = "0.2"
6667
num_enum = "0.5.7"
6768
once_cell = "1.13"

common/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ bstr = { workspace = true }
1919
cfg-if = { workspace = true }
2020
itertools = { workspace = true }
2121
libc = { workspace = true }
22-
num-bigint = { workspace = true }
22+
malachite-bigint = { workspace = true }
23+
malachite-q = { workspace = true }
24+
malachite-base = { workspace = true }
25+
num-complex = { workspace = true }
2326
num-traits = { workspace = true }
2427
once_cell = { workspace = true }
2528
parking_lot = { workspace = true, optional = true }

common/src/float_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use num_bigint::{BigInt, ToBigInt};
1+
use malachite_bigint::{BigInt, ToBigInt};
22
use num_traits::{Float, Signed, ToPrimitive, Zero};
33
use std::f64;
44

@@ -20,7 +20,7 @@ pub fn ufrexp(value: f64) -> (f64, i32) {
2020
/// # Examples
2121
///
2222
/// ```
23-
/// use num_bigint::BigInt;
23+
/// use malachite_bigint::BigInt;
2424
/// use rustpython_common::float_ops::eq_int;
2525
/// let a = 1.0f64;
2626
/// let b = BigInt::from(1);

common/src/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use num_bigint::BigInt;
1+
use malachite_bigint::BigInt;
22
use num_traits::ToPrimitive;
33
use siphasher::sip::SipHasher24;
44
use std::hash::{BuildHasher, Hash, Hasher};

common/src/int.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
use bstr::ByteSlice;
2-
use num_bigint::{BigInt, BigUint, Sign};
3-
use num_traits::{ToPrimitive, Zero};
2+
use malachite_base::{num::conversion::traits::RoundingInto, rounding_modes::RoundingMode};
3+
use malachite_bigint::{BigInt, BigUint, Sign};
4+
use malachite_q::Rational;
5+
use num_traits::{One, ToPrimitive, Zero};
6+
7+
pub fn true_div(numerator: &BigInt, denominator: &BigInt) -> f64 {
8+
let val: f64 = Rational::from_integers_ref(numerator.into(), denominator.into())
9+
.rounding_into(RoundingMode::Nearest);
10+
11+
if val == f64::MAX || val == f64::MIN {
12+
// FIXME: not possible for available ratio?
13+
return f64::INFINITY;
14+
}
15+
val
16+
}
17+
18+
pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
19+
let sign = match std::cmp::PartialOrd::partial_cmp(&value, &0.0)? {
20+
std::cmp::Ordering::Less => Sign::Minus,
21+
std::cmp::Ordering::Equal => return Some((BigInt::zero(), BigInt::one())),
22+
std::cmp::Ordering::Greater => Sign::Plus,
23+
};
24+
Rational::try_from(value).ok().map(|x| {
25+
let (numer, denom) = x.into_numerator_and_denominator();
26+
(
27+
BigInt::from_biguint(sign, numer.into()),
28+
BigUint::from(denom).into(),
29+
)
30+
})
31+
}
432

533
pub fn bytes_to_int(lit: &[u8], mut base: u32) -> Option<BigInt> {
634
// split sign

compiler/codegen/src/compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,10 +2942,10 @@ impl ToU32 for usize {
29422942
mod tests {
29432943
use super::*;
29442944
use rustpython_parser as parser;
2945-
use rustpython_parser_core::source_code::SourceLocator;
2945+
use rustpython_parser_core::source_code::LinearLocator;
29462946

29472947
fn compile_exec(source: &str) -> CodeObject {
2948-
let mut locator: SourceLocator = SourceLocator::new(source);
2948+
let mut locator: LinearLocator = LinearLocator::new(source);
29492949
use rustpython_parser::ast::fold::Fold;
29502950
let mut compiler: Compiler = Compiler::new(
29512951
CompileOpts::default(),

compiler/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rustpython-parser-core = { workspace = true }
1212

1313
bitflags = { workspace = true }
1414
itertools = { workspace = true }
15-
num-bigint = { workspace = true }
15+
malachite-bigint = { workspace = true }
1616
num-complex = { workspace = true }
1717
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
1818

compiler/core/src/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use bitflags::bitflags;
55
use itertools::Itertools;
6-
use num_bigint::BigInt;
6+
use malachite_bigint::BigInt;
77
use num_complex::Complex64;
88
use rustpython_parser_core::source_code::{OneIndexed, SourceLocation};
99
use std::marker::PhantomData;

compiler/core/src/marshal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bytecode::*;
2-
use num_bigint::{BigInt, Sign};
2+
use malachite_bigint::{BigInt, Sign};
33
use num_complex::Complex64;
44
use rustpython_parser_core::source_code::{OneIndexed, SourceLocation};
55
use std::convert::Infallible;

0 commit comments

Comments
 (0)