Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Apr 4, 2020

A 32-bit target could create a giant BigUint over 2²⁹ bytes = 512MB,
not that this would be computationally useful, but that value would have
more than usize::MAX bits. To avoid that possibility of overflow, we
can better represent bit counts in u64.

For 64-bit targets, a BigUint over 2⁶¹ bytes is not realistic.

This changes the public API in the return values of bits() and
trailing_zeros(), as well as the bit_size parameter of RandBigInt
and RandomBits. Trying to randomize an absurd size will naturally
cause a capacity overflow, just as if you'd made a huge Vec.

A 32-bit target _could_ create a giant `BigUint` over 2²⁹ bytes = 512MB,
not that this would be computationally useful, but that value would have
more than `usize::MAX` bits. To avoid that possibility of overflow, we
can better represent bit counts in `u64`.

For 64-bit targets, a `BigUint` over 2⁶¹ bytes is not realistic.

This changes the public API in the return values of `bits()` and
`trailing_zeros()`, as well as the `bit_size` parameter of `RandBigInt`
and `RandomBits`. Trying to randomize an absurd size will naturally
cause a capacity overflow, just as if you'd made a huge `Vec`.
@cuviper
Copy link
Member Author

cuviper commented Apr 4, 2020

I'm not certain this is a good idea -- I'll think on it for a bit before merging. Feedback welcome!

@cuviper
Copy link
Member Author

cuviper commented Apr 14, 2020

Ah, let's do it. If this makes it to 0.3 and folks complain, there's always 0.4 and beyond...

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 15, 2020

Build succeeded:

@bors bors bot merged commit ee2b80b into rust-num:master Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant