Contributors: @cuviper, @ralphtandetzky, @yhx-12243
- Upgrade to 2021 edition, MSRV 1.60
- Add
const ZERO
and implementnum_traits::ConstZero
- Add
modinv
methods for the modular inverse - Optimize multiplication with imbalanced operands
- Optimize scalar division on x86 and x86-64
Contributors: @cuviper, @joelonsql, @waywardmonkeys
- Implemented
From<bool>
forBigInt
andBigUint
. - Implemented
num_traits::Euclid
andCheckedEuclid
forBigInt
andBigUint
. - Implemented ties-to-even for
BigInt
andBigUint::to_f32
andto_f64
. - Implemented
num_traits::FromBytes
andToBytes
forBigInt
andBigUint
. - Limited pre-allocation from serde size hints against potential OOM.
- Miscellaneous other code cleanups and maintenance tasks.
Contributors: @AaronKutch, @archseer, @cuviper, @dramforever, @icecream17, @icedrocket, @janmarthedal, @jaybosamiya, @OliveIsAWord, @PatrickNorton, @smoelius, @waywardmonkeys
Contributors: @arvidn, @cuviper, @guidovranken
Contributors: @catenacyber, @cuviper
- Fixed scalar divide-by-zero panics.
- Implemented
DoubleEndedIterator
forU32Digits
andU64Digits
. - Optimized multiplication to avoid unnecessary allocations.
- Optimized string formatting for very large values.
Contributors: @cuviper, @PatrickNorton
- Updated public dependences on arbitrary, quickcheck, and rand:
arbitrary
support has been updated to 1.0, requiring Rust 1.40.quickcheck
support has been updated to 1.0, requiring Rust 1.46.rand
support has been updated to 0.8, requiring Rust 1.36.
Debug
now shows plain numeric values forBigInt
andBigUint
, rather than the raw list of internal digits.
Contributors: @cuviper, @Gelbpunkt
Contributors: @catenacyber, @cuviper
- The new
BigUint
methodscount_ones
andtrailing_ones
return the number of1
bits in the entire value or just its least-significant tail, respectively. - The new
BigInt
andBigUint
methodsbit
andset_bit
will read and write individual bits of the value. For negativeBigInt
, bits are determined as if they were in the two's complement representation. - The
from_radix_le
andfrom_radix_be
methods now accept empty buffers to represent zero. BigInt
andBigUint
can now iterate digits asu32
oru64
, regardless of the actual internal digit size.
Contributors: @BartMassey, @cuviper, @janmarthedal, @sebastianv89, @Speedy37
- Addition and subtraction now uses intrinsics for performance on
x86
andx86_64
when built with Rust 1.33 or later. - Conversions
to_f32
andto_f64
now return infinity for very large numbers, rather thanNone
. This does preserve the sign too, so a large negativeBigInt
will convert to negative infinity. - The optional
arbitrary
feature implementsarbitrary::Arbitrary
, distinct fromquickcheck::Arbitrary
. - The division algorithm has been optimized to reduce the number of temporary allocations and improve the internal guesses at each step.
BigInt
andBigUint
will opportunistically shrink capacity if the internal vector is much larger than needed.
Contributors: @cuviper, @e00E, @ejmahler, @notoria, @tczajka
- The internal
BigDigit
may now be eitheru32
oru64
, although that implementation detail is not exposed in the API. For now, this is chosen to match the target pointer size, but may change in the future. - No-
std
is now supported with thealloc
crate on Rust 1.36. Pow
is now implemented for bigint values, not just references.TryFrom
is now implemented on Rust 1.34 and later, converting signed integers to unsigned, and narrowing big integers to primitives.Shl
andShr
are now implemented for a variety of shift types.- A new
trailing_zeros()
returns the number of consecutive zeros from the least significant bit. - The new
BigInt::magnitude
andinto_parts
methods give access to itsBigUint
part as the magnitude.
num-bigint
now requires Rust 1.31 or greater.- The "i128" opt-in feature was removed, now always available.
- Updated public dependences:
rand
support has been updated to 0.7, requiring Rust 1.32.quickcheck
support has been updated to 0.9, requiring Rust 1.34.
- Removed
impl Neg for BigUint
, which only ever panicked. - Bit counts are now
u64
instead ofusize
.
Contributors: @cuviper, @dignifiedquire, @hansihe, @kpcyrd, @milesand, @tech6hutch
Contributors: @cuviper, @HactarCE
Contributors: @cuviper, @tspiteri
- The new
BigUint::to_u32_digits
method returns the number as a little-endian vector of base-232 digits. The same method onBigInt
also returns the sign. BigUint::modpow
now applies a modulus even for exponent 1, which also affectsBigInt::modpow
.BigInt::modpow
now returns the correct sign for negative bases with even exponents.
Contributors: @alex-ozdemir, @cuviper, @dingelish, @Speedy37, @youknowone
Pow
is now implemented forBigUint
exponents.- The optional
quickcheck
feature enables implementations ofArbitrary
. - See the full comparison for performance enhancements and more!
Contributors: @cuviper, @lcnr, @maxbla, @mikelodder7, @mikong, @TheLetterTheta, @tspiteri, @XAMPPRocky, @youknowone
- The
Roots
implementations now use better initial guesses. - Fixed
to_signed_bytes_*
for some positive numbers, where the most-significant byte is0x80
and the rest are0
.
Contributors: @cuviper, @leodasvacas
RandBigInt
now usesRng::fill_bytes
to improve performance, instead of repeatedgen::<u32>
calls. The also affects the implementations of the otherrand
traits. This may potentially change the values produced by some seeded RNGs on previous versions, but the values were tested to be stable withChaChaRng
,IsaacRng
, andXorShiftRng
.BigInt
andBigUint
now implementnum_integer::Roots
.BigInt
andBigUint
now implementnum_traits::Pow
.BigInt
andBigUint
now implement operators with 128-bit integers.
Contributors: @cuviper, @dignifiedquire, @mancabizjak, @Robbepop, @TheIronBorn, @thomwiggers
BigInt
andBigUint
now implementProduct
andSum
for iterators of any item that we canMul
andAdd
, respectively. For example, a factorial can now be simply:let f: BigUint = (1u32..1000).product();
BigInt
now supports two's-complement logic operations, namelyBitAnd
,BitOr
,BitXor
, andNot
. These act conceptually as if each number had an infinite prefix of0
or1
bits for positive or negative.BigInt
now supports assignment operators likeAddAssign
.BigInt
andBigUint
now support conversions withi128
andu128
, if sufficient compiler support is detected.BigInt
andBigUint
now implement rand'sSampleUniform
trait, and a customRandomBits
distribution samples by bit size.- The release also includes other miscellaneous improvements to performance.
num-bigint
now requires rustc 1.15 or greater.- The crate now has a
std
feature, and won't build without it. This is in preparation for someday supporting#![no_std]
withalloc
. - The
serde
dependency has been updated to 1.0, still disabled by default. Therustc-serialize
crate is no longer supported bynum-bigint
. - The
rand
dependency has been updated to 0.5, now disabled by default. This requires rustc 1.22 or greater forrand
's own requirement. Shr for BigInt
now rounds down rather than toward zero, matching the behavior of the primitive integers for negative values.ParseBigIntError
is now an opaque type.- The
big_digit
module is no longer public, nor are theBigDigit
andDoubleBigDigit
types andZERO_BIG_DIGIT
constant that were re-exported in the crate root. Public APIs which deal in digits, likeBigUint::from_slice
, will now always be base-u32
.
Contributors: @clarcharr, @cuviper, @dodomorandi, @tiehuis, @tspiteri
- Division with single-digit divisors is now much faster.
- The README now compares
ramp
,rug
,rust-gmp
, andapint
.
Contributors: @cuviper, @Robbepop
- The new
BigInt::modpow
performs signed modular exponentiation, using the existingBigUint::modpow
and rounding negatives similar tomod_floor
.
Contributors: @cuviper
- num-bigint now has its own source repository at rust-num/num-bigint.
lcm
now avoids creating a large intermediate product.gcd
now uses Stein's algorithm with faster shifts instead of division.rand
support is now extended to 0.4 (while still allowing 0.3).
Contributors: @cuviper, @Emerentius, @ignatenkobrain, @mhogrefe
No prior release notes were kept. Thanks all the same to the many contributors that have made this crate what it is!