Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e520bda
Add scalar multiplication to BigUint, BigInt
feadoor Oct 24, 2016
a2a28c6
Scalar addition of BigDigit to BigUint
feadoor Jun 28, 2017
7b7799e
Scalar subtraction of a BigDigit from a BigUint
feadoor Jun 28, 2017
530e2f6
Fix typo in comment in division algorithm
feadoor Jun 28, 2017
784d26b
Scalar division of a BigUint by a BigDigit
feadoor Jun 28, 2017
e5ed503
Implement all variants of adding BigDigit to BigUint
feadoor Jun 29, 2017
fd2f516
All variants of multiplying BigUint by BigDigit
feadoor Jun 29, 2017
5738141
Distinction for commutative scalar ops
feadoor Jun 29, 2017
51408a9
All variants of subtracting BigDigit from BigUint
feadoor Jun 29, 2017
d0bfb54
All variants of dividing BigUint by BigDigit
feadoor Jun 29, 2017
1e26bdd
Remove unnecessary normalization
feadoor Jun 29, 2017
80feea2
Also implement scalar addition for BigInt
feadoor Jun 29, 2017
79448cb
Add scalar subtraction to BigInt
feadoor Jun 29, 2017
8b1288e
Add scalar multiplication to BigInt
feadoor Jun 29, 2017
9b0392d
Add scalar division to BigInt
feadoor Jun 29, 2017
94d5706
Add operations on i32 to BigInt
feadoor Jun 29, 2017
99873d0
Scalar operations on integer types up to 32 bits
feadoor Jun 29, 2017
3f32ad4
rational: make sure Hash agrees with Eq
cuviper Jun 29, 2017
fd87d87
Fix normalization in scalar addition
feadoor Jun 29, 2017
2a3cd41
Add scalar ops for all remaining integer types
feadoor Jun 29, 2017
1fb03ca
Make new code work on rustc-1.8.0
feadoor Jun 29, 2017
5f3a3b0
Derive ToPrimitive for enums
PlasmaPower Jul 8, 2017
f0fa65a
Fix float NaN pos/neg assumptions
PlasmaPower Jul 8, 2017
aaa4ab3
Clarify what "newer versions of Rust" applies to
PlasmaPower Jul 8, 2017
3299702
Whitelist branches for CI
cuviper Jul 9, 2017
b181cae
Enable bors-ng
cuviper Jul 9, 2017
31fa9f6
Merge pull request #316 from cuviper/bors-ng
cuviper Jul 9, 2017
426034b
Switch doctests to match functions
PlasmaPower Jul 9, 2017
36b492a
Merge #315
bors[bot] Jul 10, 2017
bcccab1
Merge #311
bors[bot] Jul 10, 2017
eddcb54
Add cargo keywords and categories.
kw217 Jul 10, 2017
c87faf4
Tweak categories based on review.
kw217 Jul 11, 2017
ef83e85
Add keywords and categories to subcrates too.
kw217 Jul 11, 2017
26af99c
Merge #318
bors[bot] Jul 11, 2017
73a2dfd
Merge #314
bors[bot] Jul 11, 2017
18cc190
inline i32_abs_as_u32 and i64_abs_as_u64
cuviper Jul 12, 2017
18a5bfc
fix endianness of to/from_doublebigdigit calls
cuviper Jul 12, 2017
6afac82
test and fix more scalar add cases
cuviper Jul 12, 2017
e5434dc
Add assert_scalar_op! for DRYer testing
cuviper Jul 12, 2017
ebc36b3
Merge #313
bors[bot] Jul 12, 2017
5beed1a
Merge branch 'master' into next
cuviper Jul 12, 2017
415a9bf
Update the default Float signs more like current Rust
cuviper Jul 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ after_success: |
notifications:
email:
on_success: never
branches:
only:
- master
- next
- staging
- trying
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ authors = ["The Rust Project Developers"]
description = "A collection of numeric types and traits for Rust, including bigint,\ncomplex, rational, range iterators, generic integers, and more!\n"
documentation = "http://rust-num.github.io/num"
homepage = "https://github.com/rust-num/num"
keywords = ["mathematics", "numerics"]
keywords = ["mathematics", "numerics", "bignum"]
categories = [ "algorithms", "data-structures", "science" ]
license = "MIT/Apache-2.0"
repository = "https://github.com/rust-num/num"
name = "num"
Expand Down
3 changes: 2 additions & 1 deletion bigint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ authors = ["The Rust Project Developers"]
description = "Big integer implementation for Rust"
documentation = "http://rust-num.github.io/num"
homepage = "https://github.com/rust-num/num"
keywords = ["mathematics", "numerics"]
keywords = ["mathematics", "numerics", "bignum"]
categories = [ "algorithms", "data-structures", "science" ]
license = "MIT/Apache-2.0"
name = "num-bigint"
repository = "https://github.com/rust-num/num"
Expand Down
19 changes: 18 additions & 1 deletion bigint/src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ pub fn mac_with_carry(a: BigDigit, b: BigDigit, c: BigDigit, carry: &mut BigDigi
lo
}

#[inline]
pub fn mul_with_carry(a: BigDigit, b: BigDigit, carry: &mut BigDigit) -> BigDigit {
let (hi, lo) = big_digit::from_doublebigdigit((a as DoubleBigDigit) * (b as DoubleBigDigit) +
(*carry as DoubleBigDigit));

*carry = hi;
lo
}

/// Divide a two digit numerator by a one digit divisor, returns quotient and remainder:
///
/// Note: the caller must ensure that both the quotient and remainder will fit into a single digit.
Expand Down Expand Up @@ -377,6 +386,14 @@ pub fn mul3(x: &[BigDigit], y: &[BigDigit]) -> BigUint {
prod.normalize()
}

pub fn scalar_mul(a: &mut [BigDigit], b: BigDigit) -> BigDigit {
let mut carry = 0;
for a in a.iter_mut() {
*a = mul_with_carry(*a, b, &mut carry);
}
carry
}

pub fn div_rem(u: &BigUint, d: &BigUint) -> (BigUint, BigUint) {
if d.is_zero() {
panic!()
Expand Down Expand Up @@ -416,7 +433,7 @@ pub fn div_rem(u: &BigUint, d: &BigUint) -> (BigUint, BigUint) {
// q0, our guess, is calculated by dividing the last few digits of a by the last digit of b
// - this should give us a guess that is "close" to the actual quotient, but is possibly
// greater than the actual quotient. If q0 * b > a, we simply use iterated subtraction
// until we have a guess such that q0 & b <= a.
// until we have a guess such that q0 * b <= a.
//

let bn = *b.data.last().unwrap();
Expand Down
Loading